Ronio Jerico Roque commited on
Commit
792e40c
·
1 Parent(s): 8811d54

Add Streamlit configuration and implement Target Market Analyst functionality

Browse files
.streamlit/config.toml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [client]
2
+ showSidebarNavigation = false
3
+
4
+ [runner]
5
+ fastReruns = true
6
+
7
+ [browser]
8
+ gatherUsageStats = false
9
+
10
+ [global]
11
+ disableWidgetStateDuplicationWarning = true
classes/Target_Market.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from newsapi import NewsApiClient
12
+
13
+ class TargetMarketAnalyst:
14
+ def __init__(self, model_url, analyst_name, data_src, analyst_description):
15
+ self.newsapi = NewsApiClient(api_key='ae72168bf4064434bef650d038624373')
16
+ self.model_url = model_url
17
+ self.analyst_name = analyst_name
18
+ self.data_src = data_src
19
+ self.analyst_description = analyst_description
20
+ self.initialize()
21
+ self.row1()
22
+
23
+ def initialize(self):
24
+ # FOR ENV
25
+ load_dotenv()
26
+
27
+ # AGENT NAME
28
+ st.header(self.analyst_name)
29
+
30
+ # EVALUATION FORM LINK
31
+ url = os.getenv('Link')
32
+ st.write('Evaluation Form: [Link](%s)' % url)
33
+
34
+ # RETURN BUTTON
35
+ try:
36
+ if st.button("Return", type='primary'):
37
+ st.switch_page("./pages/home.py")
38
+ except Exception:
39
+ pass
40
+
41
+ def request_model(self, payload_txt):
42
+ response = requests.post(self.model_url, json=payload_txt)
43
+ sources = self.newsapi.get_sources()
44
+ response.raise_for_status()
45
+ output = response.json()
46
+
47
+ text = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]
48
+ text = json.loads(text)
49
+ text = text[0]
50
+
51
+ target_market = text["target_market"]
52
+ demographics = text["demographics"]
53
+ summary = text["summary"]
54
+
55
+ with st.expander("AI Analyst", expanded=True, icon="🤖"):
56
+ st.write(f"**Target Market**:\n {target_market}\n")
57
+ st.write(f"\n**Product / Service Demographics**: {demographics}")
58
+ st.write(f"\n**Marketing Message Summary**: {summary}")
59
+
60
+ return output
61
+
62
+ def row1(self):
63
+ col1, col2 = st.columns(gap="medium", spec=[0.33, 0.66])
64
+ with col1:
65
+ self.topics = st.text_input("Topic/s of Interest: ", placeholder='Enter Topic/s of Interest:', key='topic')
66
+
67
+ with col2:
68
+ st.write("") # FOR THE HIDE BUTTON
69
+ st.write("") # FOR THE HIDE BUTTON
70
+ st.write("AI Analyst Output: ")
71
+ st.session_state['analyzing'] = False
72
+ st.write("") # FOR THE HIDE BUTTON
73
+ analyze_button = st.button("Analyze", disabled=initialize_analyze_session())
74
+ start_time = time.time()
75
+ if analyze_button:
76
+ hide_button()
77
+ if self.topics or self.sources and self.country:
78
+ combined_text = ""
79
+ with st.spinner('Analyzing...', show_time=True):
80
+ st.write('')
81
+ # INITIALIZING SESSIONS
82
+
83
+ combined_text += f"Topic/s of Interest: {self.topics}\n"
84
+
85
+
86
+ # OUTPUT FOR SEO ANALYST
87
+ root = 'https://newsapi.org/v2/everything?'
88
+ query = f'q={self.topics}'
89
+ response = requests.get(f'{root}{query}&from=2025-03-20&to=2025-03-20&sortBy=popularity&apiKey=ae72168bf4064434bef650d038624373')
90
+ response.raise_for_status()
91
+ output = response.json()
92
+
93
+ st.write(output)
94
+
95
+
96
+ end_time = time.time()
97
+ time_lapsed = end_time - start_time
98
+ debug_info = {
99
+ 'analyst': self.analyst_name,
100
+ 'time_lapsed': time_lapsed,
101
+
102
+ }
103
+
104
+ collect_telemetry(debug_info)
105
+
106
+ with st.expander("Debug information", icon="⚙"):
107
+ st.write(debug_info)
108
+
109
+ st.session_state['analyzing'] = False
110
+ else:
111
+ st.info("Please upload CSV or PDF files first.")
112
+ hide_button()
113
+
114
+ if __name__ == "__main__":
115
+ st.set_page_config(layout="wide")
116
+
117
+ upload = uploadFile()
helper/button_behaviour.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def hide_button():
4
+ st.markdown(
5
+ """
6
+ <style>
7
+ .element-container:nth-of-type(5) button {
8
+ display: none;
9
+ }
10
+ </style>
11
+ """,
12
+ unsafe_allow_html=True,
13
+ )
14
+
15
+ def unhide_button():
16
+ st.markdown(
17
+ """
18
+ <style>
19
+ element-container:nth-of-type(5) button {
20
+ display: inline;
21
+ }
22
+ </style>
23
+ """,
24
+ unsafe_allow_html=True,
25
+ )