Ronio Jerico Roque commited on
Commit
6d0d15b
·
1 Parent(s): 3b3ebe2

Add ConnectionAnalyst class and integrate into analyzing_page for connection analysis

Browse files
classes/response_connection_analyst.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from dotenv import load_dotenv
4
+ import os
5
+ from helper.upload_response import upload_response
6
+ from helper.upload_File import uploadFile
7
+ from pymongo import MongoClient
8
+ import json
9
+
10
+ class ConnectionAnalyst:
11
+ def __init__(self, model_url):
12
+ self.uploaded_files = []
13
+ self.file_dict = {}
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
+ def request_model(self, payload_txt, headers):
29
+ response = requests.post(self.model_url, json=payload_txt, headers=headers)
30
+ response.raise_for_status()
31
+ output = response.json()
32
+ #st.write(output)
33
+ text = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]
34
+ #text = json.loads(text)
35
+ #st.write(text)
36
+ return text
37
+
38
+ def fetch_data(self, data_field):
39
+ mongodb_uri = os.getenv("MONGODB_URI")
40
+ myclient = MongoClient(mongodb_uri)
41
+ mydb = myclient.get_database()
42
+ mycol = mydb["df_data"]
43
+
44
+ # Sort by timestamp field in descending order
45
+ x = mycol.find_one(
46
+ {"data_field": data_field},
47
+ sort=[("timestamp", -1)]
48
+ )
49
+
50
+ x = x["result"]
51
+ return x
52
+
53
+ def process(self):
54
+ with st.spinner('Connection Analyst...', show_time=True):
55
+ st.write('')
56
+ headers = {"Content-Type": "application/json", "x-api-key": f"{os.getenv('x-api-key')}"}
57
+ try:
58
+ payload_txt = {"input_value": self.payload, "output_type": "text", "input_type": "chat"}
59
+ payload_txt_model = self.request_model(payload_txt, headers)
60
+ debug_info = {'data_field' : 'Connection Analyst', 'result': payload_txt_model}
61
+ upload_response(debug_info)
62
+
63
+ count = 0
64
+ except Exception as e:
65
+ pass
66
+ st.session_state['analyzing'] = False
67
+
68
+ def row1(self):
69
+ st.session_state['analyzing'] = False
70
+ self.payload = ""
71
+ count = 0
72
+ try:
73
+ session_client_summary = st.session_state['client_summary']
74
+ if session_client_summary == 'uploaded':
75
+ count += 1
76
+ self.payload += self.fetch_data("Client Summary")
77
+ except Exception as e:
78
+ pass
79
+
80
+ if count >= 1:
81
+ self.process()
82
+
83
+
84
+ if __name__ == "__main__":
85
+ st.set_page_config(layout="wide")
86
+
87
+ upload = uploadFile()
pages/analyzing_page.py CHANGED
@@ -19,6 +19,7 @@ from classes.response_desired_outcome import DesiredOutcome
19
  from classes.response_conversion_analyst import ConversionAnalyst
20
  from classes.response_website_audience_acquisition import WebsiteAudienceAcquisition
21
  from classes.response_content_process_and_assets_analyst import Content_Process_and_Assets_Analyst
 
22
  from classes.response_executive_summary import ExecutiveSummary
23
  from classes.response_snapshot import Snapshot
24
 
@@ -76,6 +77,7 @@ def run_analysis():
76
  "conversion": st.empty(),
77
  "website_audience": st.empty(),
78
  "content_process_and_assets": st.empty(),
 
79
  "snapshot": st.empty(),
80
  "executive_summary": st.empty(),
81
 
@@ -262,6 +264,17 @@ def run_analysis():
262
  handler.update_error(f"Content - Process and Assets Analysis failed: {str(e)}")
263
  return None
264
 
 
 
 
 
 
 
 
 
 
 
 
265
  def run_snapshot_analysis():
266
  handler = handlers["snapshot"]
267
  try:
@@ -301,7 +314,8 @@ def run_analysis():
301
  (run_desired_outcomes_analysis, "desired_outcome"),
302
  (run_content_process_and_assets_analysis, "content_process_and_assets"),
303
  (run_conversion_analysis, "conversion"),
304
- (run_website_audience, "website_audience")
 
305
  ]
306
 
307
  # Create and start first batch threads with small delays to prevent UI conflicts
 
19
  from classes.response_conversion_analyst import ConversionAnalyst
20
  from classes.response_website_audience_acquisition import WebsiteAudienceAcquisition
21
  from classes.response_content_process_and_assets_analyst import Content_Process_and_Assets_Analyst
22
+ from classes.response_connection_analyst import ConnectionAnalyst
23
  from classes.response_executive_summary import ExecutiveSummary
24
  from classes.response_snapshot import Snapshot
25
 
 
77
  "conversion": st.empty(),
78
  "website_audience": st.empty(),
79
  "content_process_and_assets": st.empty(),
80
+ "connection": st.empty(),
81
  "snapshot": st.empty(),
82
  "executive_summary": st.empty(),
83
 
 
264
  handler.update_error(f"Content - Process and Assets Analysis failed: {str(e)}")
265
  return None
266
 
267
+ def run_connection_analysis():
268
+ handler = handlers["connection"]
269
+ try:
270
+ handler.update_info("Connection Analysis...")
271
+ result = ConnectionAnalyst(os.getenv('Model_Connection_Analyst'))
272
+ handler.update_success("Connection Analysis completed successfully.")
273
+ return result
274
+ except Exception as e:
275
+ handler.update_error(f"Connection Analysis failed: {str(e)}")
276
+ return None
277
+
278
  def run_snapshot_analysis():
279
  handler = handlers["snapshot"]
280
  try:
 
314
  (run_desired_outcomes_analysis, "desired_outcome"),
315
  (run_content_process_and_assets_analysis, "content_process_and_assets"),
316
  (run_conversion_analysis, "conversion"),
317
+ (run_website_audience, "website_audience"),
318
+ (run_connection_analysis, "connection")
319
  ]
320
 
321
  # Create and start first batch threads with small delays to prevent UI conflicts