Ronio Jerico Roque commited on
Commit
e23525d
·
1 Parent(s): 6bea16c

Add Executive Summary analysis functionality and integrate into analyzing page

Browse files
classes/response_executive_summary.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from urllib.parse import urlparse
2
+ import streamlit as st
3
+ import requests
4
+ from dotenv import load_dotenv
5
+ import os
6
+ from helper.upload_response import upload_response
7
+ from helper.upload_File import uploadFile
8
+ import json
9
+ from pymongo import MongoClient
10
+ from helper.data_field import get_analyst_response
11
+
12
+
13
+ class ExecutiveSummary:
14
+ def __init__(self, model_url):
15
+ self.uploaded_files = []
16
+ self.file_dict = {}
17
+ self.model_url = model_url
18
+ #self.analyst_name = analyst_name
19
+ #self.data_src = data_src
20
+ #self.analyst_description = analyst_description
21
+ self.initialize()
22
+ self.row1()
23
+
24
+ def initialize(self):
25
+ # FOR ENV
26
+ load_dotenv()
27
+
28
+ # AGENT NAME
29
+ #st.header(self.analyst_name)
30
+
31
+ def request_model(self, payload_txt, headers):
32
+ response = requests.post(self.model_url, json=payload_txt, headers=headers)
33
+ response.raise_for_status()
34
+ output = response.json()
35
+ #st.write(output)
36
+ text = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]
37
+ text = json.loads(text)
38
+ #st.write(text)
39
+ return text
40
+
41
+ def fetch_data(self, data_field):
42
+ mongodb_uri = os.getenv("MONGODB_URI")
43
+ myclient = MongoClient(mongodb_uri)
44
+ mydb = myclient.get_database()
45
+ mycol = mydb["df_data"]
46
+
47
+ # Sort by timestamp field in descending order
48
+ x = mycol.find_one(
49
+ {"data_field": data_field},
50
+ sort=[("timestamp", -1)]
51
+ )
52
+
53
+ x = x["result"]
54
+ return x
55
+
56
+ def process(self):
57
+ with st.spinner('Executive Summary...', show_time=True):
58
+ st.write('')
59
+ headers = {"Content-Type": "application/json", "x-api-key": f"{os.getenv('x-api-key')}"}
60
+ try:
61
+ payload_txt = {"input_value": self.payload, "output_type": "text", "input_type": "chat"}
62
+ payload_txt_model = self.request_model(payload_txt, headers)
63
+ debug_info = {'data_field' : 'Executive Summary', 'result': payload_txt_model}
64
+ upload_response(debug_info)
65
+
66
+ except Exception as e:
67
+ pass
68
+ st.session_state['analyzing'] = False
69
+
70
+ def row1(self):
71
+ st.session_state['analyzing'] = False
72
+ self.payload = ""
73
+
74
+ self.website_and_tools_data = get_analyst_response("Website and Tools Analyst")
75
+ self.sem_data = get_analyst_response("SEM/PPC Analyst")
76
+ self.seo_data = get_analyst_response("SEO Analyst")
77
+ self.on_page_data = get_analyst_response("On Page Analyst")
78
+ self.off_page_data = get_analyst_response("Off Page Analyst")
79
+ self.social_media_data = get_analyst_response("Social Media Analyst")
80
+ self.content_data = get_analyst_response("Content Analyst")
81
+ self.marketpalce_data = get_analyst_response("Marketplace Analyst")
82
+ self.target_market_data = get_analyst_response("Target Market Analyst")
83
+ self.website_audience_data = get_analyst_response("Pull through offers Analyst")
84
+ self.pull_through_data = get_analyst_response("Website Audience Acquisition Analyst")
85
+ self.lld_data = get_analyst_response("LLD/PM/LN Analyst")
86
+ self.pna_data = get_analyst_response("Content - Process and Assets Analyst")
87
+
88
+ analyst_data_dict = {
89
+ "Website and Tools": self.website_and_tools_data,
90
+ "SEM/PPC": self.sem_data,
91
+ "SEO": self.seo_data,
92
+ "On Page": self.on_page_data,
93
+ "Off Page": self.off_page_data,
94
+ "Social Media": self.social_media_data,
95
+ "Content": self.content_data,
96
+ "Marketplace": self.marketpalce_data,
97
+ "Target Market": self.target_market_data,
98
+ "Pull through offers": self.website_audience_data,
99
+ "Website Audience Acquisition": self.pull_through_data,
100
+ "LLD/PM/LN": self.lld_data,
101
+ "Content - Process and Assets": self.pna_data
102
+ }
103
+
104
+
105
+ for analyst_name, data in analyst_data_dict.items():
106
+ self.payload += f"\n\n--- {analyst_name} Analysis ---\n"
107
+ if isinstance(data, list):
108
+ self.payload += "\n".join(map(str, data))
109
+ else:
110
+ self.payload += str(data)
111
+
112
+ self.process()
113
+
114
+ if __name__ == "__main__":
115
+ st.set_page_config(layout="wide")
116
+
117
+ upload = uploadFile()
pages/analyzing_page.py CHANGED
@@ -13,6 +13,7 @@ from classes.response_content import Content
13
  from classes.response_sem_ppc import Sem_PPC
14
  from classes.response_marketplace import Marketplace
15
  from classes.response_target_market import TargetMarket
 
16
 
17
  def run_analysis():
18
  # Placeholders for status updates
@@ -27,6 +28,7 @@ def run_analysis():
27
  sem_ppc = st.empty()
28
  marketplace = st.empty()
29
  target_market = st.empty()
 
30
 
31
  def run_off_page_analysis():
32
  try:
@@ -137,7 +139,17 @@ def run_analysis():
137
  except Exception as e:
138
  target_market.error(f"Target Market Analysis failed: {e}")
139
  return None
140
-
 
 
 
 
 
 
 
 
 
 
141
  # Create threads for concurrent execution
142
  off_page_thread = threading.Thread(target=run_off_page_analysis)
143
  on_page_thread = threading.Thread(target=run_on_page_analysis)
@@ -191,7 +203,13 @@ def run_analysis():
191
  target_market_thread.join()
192
 
193
  st.markdown("---")
194
- st.success("🎉 All analyses completed!") # Final success message
 
 
 
 
 
 
195
  # --- Display Button After Completion ---
196
  if st.button("View Results", icon="📃"):
197
  st.switch_page("pages/output.py")
 
13
  from classes.response_sem_ppc import Sem_PPC
14
  from classes.response_marketplace import Marketplace
15
  from classes.response_target_market import TargetMarket
16
+ from classes.response_executive_summary import ExecutiveSummary
17
 
18
  def run_analysis():
19
  # Placeholders for status updates
 
28
  sem_ppc = st.empty()
29
  marketplace = st.empty()
30
  target_market = st.empty()
31
+ executive_summary_status = st.empty()
32
 
33
  def run_off_page_analysis():
34
  try:
 
139
  except Exception as e:
140
  target_market.error(f"Target Market Analysis failed: {e}")
141
  return None
142
+
143
+ def run_executive_summary_analysis():
144
+ try:
145
+ executive_summary = st.empty().info("Starting Executive Summary Analysis...")
146
+ result = ExecutiveSummary(os.getenv('Model_Executive_Summary_Analyst'))
147
+ executive_summary = st.empty().success("Executive Summary Analysis completed successfully.")
148
+ return result
149
+ except Exception as e:
150
+ executive_summary = st.empty().error(f"Executive Summary Analysis failed: {e}")
151
+ return None
152
+
153
  # Create threads for concurrent execution
154
  off_page_thread = threading.Thread(target=run_off_page_analysis)
155
  on_page_thread = threading.Thread(target=run_on_page_analysis)
 
203
  target_market_thread.join()
204
 
205
  st.markdown("---")
206
+ executive_summary_status.info("Starting Executive Summary Analysis...")
207
+ try:
208
+ executive_summary = ExecutiveSummary(os.getenv('Model_Executive_Summary_Analyst'))
209
+ executive_summary_status.success("Executive Summary Analysis completed successfully.")
210
+ except Exception as e:
211
+ executive_summary_status.error(f"Executive Summary Analysis failed: {e}")
212
+ st.success("🎉 All analyses completed!") # Final success message
213
  # --- Display Button After Completion ---
214
  if st.button("View Results", icon="📃"):
215
  st.switch_page("pages/output.py")
pages/home.py CHANGED
@@ -54,7 +54,6 @@ class DigitalFootprintDashboard:
54
  else:
55
  st.session_state["analyze"] = ''
56
 
57
-
58
  self.analyze_button = st.button("Analyze", icon="✨", use_container_width=True)
59
  if self.analyze_button == True:
60
  st.switch_page("pages/analyzing_page.py")
 
54
  else:
55
  st.session_state["analyze"] = ''
56
 
 
57
  self.analyze_button = st.button("Analyze", icon="✨", use_container_width=True)
58
  if self.analyze_button == True:
59
  st.switch_page("pages/analyzing_page.py")
pages/output.py CHANGED
@@ -2,7 +2,7 @@ import json
2
  import os
3
  import streamlit as st
4
  from helper.data_field import get_analyst_response
5
- import time
6
 
7
  st.set_page_config(layout="centered")
8
 
@@ -111,8 +111,6 @@ def seo_on_page_table(df_data):
111
  else:
112
  st.warning("No data retrieved for analysis.")
113
  # --- End: Loop and display data ---
114
-
115
-
116
 
117
  def display_outputs():
118
  st.markdown("<div id='top'></div>", unsafe_allow_html=True);
@@ -132,6 +130,7 @@ This document represents the results of our audit of LoansOne’s digital market
132
  st.markdown(f"{overview}")
133
  st.markdown("---")
134
  st.markdown("### Executive Summary")
 
135
  st.markdown(f"Simtech LED's digital footprint reveals significant strengths and areas for improvement that can enhance its competitive positioning in the casino, gaming, and entertainment LED market. The analysis highlights the following key findings and recommendations")
136
  st.markdown("---")
137
 
@@ -241,11 +240,13 @@ Regardless, it is still a great channel worth investing to improve a business’
241
  st.write("TBD")
242
 
243
  st.markdown("##### WHAT IS THE PULL-THROUGH OFFER?")
244
- st.write(get_analyst_response("Pull through offers Analyst"))
 
245
 
246
 
247
  st.markdown("##### WEBSITE AUDIENCE ACQUISITION")
248
- st.write(get_analyst_response("Website Audience Acquisition Analyst"))
 
249
 
250
  #LLD/PM/LN
251
  lld_data = get_analyst_response("LLD/PM/LN Analyst")
@@ -301,8 +302,7 @@ We have evaluated the process of content development strategy and existing conte
301
  st.write("TBD")
302
 
303
  st.markdown("<a href='#top'>Go to top</a>", unsafe_allow_html=True)
304
-
305
-
306
  if st.button("Back to Dashboard", icon="🏠"):
307
  st.switch_page("pages/home.py")
308
  display_outputs()
 
2
  import os
3
  import streamlit as st
4
  from helper.data_field import get_analyst_response
5
+ from helper.telemetry import collect_telemetry
6
 
7
  st.set_page_config(layout="centered")
8
 
 
111
  else:
112
  st.warning("No data retrieved for analysis.")
113
  # --- End: Loop and display data ---
 
 
114
 
115
  def display_outputs():
116
  st.markdown("<div id='top'></div>", unsafe_allow_html=True);
 
130
  st.markdown(f"{overview}")
131
  st.markdown("---")
132
  st.markdown("### Executive Summary")
133
+
134
  st.markdown(f"Simtech LED's digital footprint reveals significant strengths and areas for improvement that can enhance its competitive positioning in the casino, gaming, and entertainment LED market. The analysis highlights the following key findings and recommendations")
135
  st.markdown("---")
136
 
 
240
  st.write("TBD")
241
 
242
  st.markdown("##### WHAT IS THE PULL-THROUGH OFFER?")
243
+ pull_through_data = get_analyst_response("Pull through offers Analyst")
244
+ st.write(pull_through_data)
245
 
246
 
247
  st.markdown("##### WEBSITE AUDIENCE ACQUISITION")
248
+ website_audience_data = get_analyst_response("Website Audience Acquisition Analyst")
249
+ st.write(website_audience_data)
250
 
251
  #LLD/PM/LN
252
  lld_data = get_analyst_response("LLD/PM/LN Analyst")
 
302
  st.write("TBD")
303
 
304
  st.markdown("<a href='#top'>Go to top</a>", unsafe_allow_html=True)
305
+
 
306
  if st.button("Back to Dashboard", icon="🏠"):
307
  st.switch_page("pages/home.py")
308
  display_outputs()