Ronio Jerico Roque commited on
Commit
7d8e6fa
·
1 Parent(s): 8caefd3

feat: add TargetMarketAnalyst class for analyzing target markets and demographics

Browse files
Files changed (1) hide show
  1. classes/Target_Market.py +116 -0
classes/Target_Market.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from dotenv import load_dotenv
4
+ import os
5
+ import time
6
+ from helper.telemetry import collect_telemetry
7
+ from helper.upload_File import uploadFile
8
+ from helper.button_behaviour import hide_button
9
+ from helper.initialize_analyze_session import initialize_analyze_session
10
+ import json
11
+
12
+ class TargetMarketAnalyst:
13
+ def __init__(self, model_url, analyst_name, data_src, analyst_description):
14
+ self.model_url = model_url
15
+ self.analyst_name = analyst_name
16
+ self.data_src = data_src
17
+ self.analyst_description = analyst_description
18
+ self.initialize()
19
+ self.row1()
20
+
21
+ def initialize(self):
22
+ # FOR ENV
23
+ load_dotenv()
24
+
25
+ # AGENT NAME
26
+ st.header(self.analyst_name)
27
+
28
+ # EVALUATION FORM LINK
29
+ url = os.getenv('Link')
30
+ st.write('Evaluation Form: [Link](%s)' % url)
31
+
32
+ # RETURN BUTTON
33
+ try:
34
+ if st.button("Return", type='primary'):
35
+ st.switch_page("./app.py")
36
+ except Exception:
37
+ pass
38
+
39
+ def request_model(self, payload_txt):
40
+ response = requests.post(self.model_url, json=payload_txt)
41
+ response.raise_for_status()
42
+ output = response.json()
43
+
44
+ text = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]
45
+ text = json.loads(text)
46
+ text = text[0]
47
+
48
+ target_market = text["target_market"]
49
+ demographics = text["demographics"]
50
+ summary = text["summary"]
51
+
52
+ with st.expander("AI Analyst", expanded=True, icon="🤖"):
53
+ st.write(f"**Target Market**:\n {target_market}\n")
54
+ st.write(f"\n**Product / Service Demographics**: {demographics}")
55
+ st.write(f"\n**Marketing Message Summary**: {summary}")
56
+
57
+ return output
58
+
59
+ def row1(self):
60
+ col1, col2 = st.columns(gap="medium", spec=[0.33, 0.66])
61
+ with col1:
62
+ self.business_name = st.text_input("Business Name: ", placeholder='Enter Business Name', key='business_name')
63
+ self.products = st.text_area("Product/s: ", placeholder='Enter Product/s', key='product')
64
+ self.area = st.text_input("Area of Business: ", placeholder='Enter Area of Business', key='area')
65
+ with col2:
66
+ st.write("") # FOR THE HIDE BUTTON
67
+ st.write("") # FOR THE HIDE BUTTON
68
+ st.write("AI Analyst Output: ")
69
+ st.session_state['analyzing'] = False
70
+ st.write("") # FOR THE HIDE BUTTON
71
+ analyze_button = st.button("Analyze", disabled=initialize_analyze_session())
72
+ start_time = time.time()
73
+ if analyze_button:
74
+ hide_button()
75
+ if self.business_name and self.products and self.area:
76
+ combined_text = ""
77
+ with st.spinner('Analyzing...', show_time=True):
78
+ st.write('')
79
+ # INITIALIZING SESSIONS
80
+
81
+ combined_text += f"Business Name: {self.business_name}\n"
82
+ combined_text += f"Product/s: {self.products}\n"
83
+ combined_text += f"Area of Business: {self.area}\n"
84
+
85
+
86
+ # OUTPUT FOR SEO ANALYST
87
+ payload_txt = {"input_value": combined_text,
88
+ "output_type": "text",
89
+ "input_type": "chat"
90
+ }
91
+ result = self.request_model(payload_txt)
92
+
93
+ end_time = time.time()
94
+ time_lapsed = end_time - start_time
95
+ debug_info = {
96
+ 'analyst': self.analyst_name,
97
+ 'url_uuid': self.model_url.split("-")[-1],
98
+ 'time_lapsed': time_lapsed,
99
+ 'payload': payload_txt,
100
+ 'result': result,
101
+ }
102
+
103
+ collect_telemetry(debug_info)
104
+
105
+ with st.expander("Debug information", icon="⚙"):
106
+ st.write(debug_info)
107
+
108
+ st.session_state['analyzing'] = False
109
+ else:
110
+ st.info("Please upload CSV or PDF files first.")
111
+ hide_button()
112
+
113
+ if __name__ == "__main__":
114
+ st.set_page_config(layout="wide")
115
+
116
+ upload = uploadFile()