Spaces:
Build error
Build error
Ronio Jerico Roque commited on
Commit ·
52eab69
1
Parent(s): b1fea65
Add DesiredOutcome class and integrate into analysis workflow
Browse files- classes/response_desired_outcome.py +89 -0
- pages/analyzing_page.py +18 -2
classes/response_desired_outcome.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 DesiredOutcome:
|
| 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 |
+
print(response)
|
| 32 |
+
output = response.json()
|
| 33 |
+
#st.write(output)
|
| 34 |
+
text = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]
|
| 35 |
+
#text = json.loads(text)
|
| 36 |
+
#st.write(text)
|
| 37 |
+
return text
|
| 38 |
+
|
| 39 |
+
def fetch_data(self, data_field):
|
| 40 |
+
mongodb_uri = os.getenv("MONGODB_URI")
|
| 41 |
+
myclient = MongoClient(mongodb_uri)
|
| 42 |
+
mydb = myclient.get_database()
|
| 43 |
+
mycol = mydb["df_data"]
|
| 44 |
+
|
| 45 |
+
# Sort by timestamp field in descending order
|
| 46 |
+
x = mycol.find_one(
|
| 47 |
+
{"data_field": data_field},
|
| 48 |
+
sort=[("timestamp", -1)]
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
x = x["result"]
|
| 52 |
+
return x
|
| 53 |
+
|
| 54 |
+
def process(self):
|
| 55 |
+
with st.spinner('Desired Outcome Analyst...', show_time=True):
|
| 56 |
+
st.write('')
|
| 57 |
+
headers = {"Content-Type": "application/json", "x-api-key": f"{os.getenv('x-api-key')}"}
|
| 58 |
+
try:
|
| 59 |
+
payload_txt = {"input_value": self.payload, "output_type": "text", "input_type": "chat"}
|
| 60 |
+
payload_txt_model = self.request_model(payload_txt, headers)
|
| 61 |
+
debug_info = {'data_field' : 'Desired Outcomes Analyst', 'result': payload_txt_model}
|
| 62 |
+
upload_response(debug_info)
|
| 63 |
+
|
| 64 |
+
st.session_state['client_summary'] = ''
|
| 65 |
+
count = 0
|
| 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 |
+
count = 0
|
| 74 |
+
try:
|
| 75 |
+
session_client_summary = st.session_state['client_summary']
|
| 76 |
+
if session_client_summary == 'uploaded':
|
| 77 |
+
count += 1
|
| 78 |
+
self.payload += self.fetch_data("Client Summary")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
pass
|
| 81 |
+
|
| 82 |
+
if count >= 1:
|
| 83 |
+
self.process()
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
st.set_page_config(layout="wide")
|
| 88 |
+
|
| 89 |
+
upload = uploadFile()
|
pages/analyzing_page.py
CHANGED
|
@@ -15,6 +15,7 @@ from classes.response_sem_ppc import Sem_PPC
|
|
| 15 |
from classes.response_marketplace import Marketplace
|
| 16 |
from classes.response_target_market import TargetMarket
|
| 17 |
from classes.response_df_overview import dfOverview
|
|
|
|
| 18 |
from classes.response_executive_summary import ExecutiveSummary
|
| 19 |
from classes.response_snapshot import Snapshot
|
| 20 |
|
|
@@ -68,8 +69,11 @@ def run_analysis():
|
|
| 68 |
"marketplace": st.empty(),
|
| 69 |
"target_market": st.empty(),
|
| 70 |
"df_overview": st.empty(),
|
|
|
|
|
|
|
| 71 |
"executive_summary": st.empty(),
|
| 72 |
-
|
|
|
|
| 73 |
}
|
| 74 |
|
| 75 |
# Create thread-safe handlers for each analysis type
|
|
@@ -208,6 +212,17 @@ def run_analysis():
|
|
| 208 |
except Exception as e:
|
| 209 |
handler.update_error(f"DF Overview Analysis failed: {str(e)}")
|
| 210 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
def run_snapshot_analysis():
|
| 213 |
handler = handlers["snapshot"]
|
|
@@ -244,7 +259,8 @@ def run_analysis():
|
|
| 244 |
(run_sem_ppc_analysis, "sem_ppc"),
|
| 245 |
(run_marketplace_analysis, "marketplace"),
|
| 246 |
(run_target_market_analysis, "target_market"),
|
| 247 |
-
(run_df_overview_analysis, "df_overview")
|
|
|
|
| 248 |
]
|
| 249 |
|
| 250 |
# Create and start first batch threads with small delays to prevent UI conflicts
|
|
|
|
| 15 |
from classes.response_marketplace import Marketplace
|
| 16 |
from classes.response_target_market import TargetMarket
|
| 17 |
from classes.response_df_overview import dfOverview
|
| 18 |
+
from classes.response_desired_outcome import DesiredOutcome
|
| 19 |
from classes.response_executive_summary import ExecutiveSummary
|
| 20 |
from classes.response_snapshot import Snapshot
|
| 21 |
|
|
|
|
| 69 |
"marketplace": st.empty(),
|
| 70 |
"target_market": st.empty(),
|
| 71 |
"df_overview": st.empty(),
|
| 72 |
+
"desired_outcome": st.empty(),
|
| 73 |
+
"snapshot": st.empty(),
|
| 74 |
"executive_summary": st.empty(),
|
| 75 |
+
|
| 76 |
+
|
| 77 |
}
|
| 78 |
|
| 79 |
# Create thread-safe handlers for each analysis type
|
|
|
|
| 212 |
except Exception as e:
|
| 213 |
handler.update_error(f"DF Overview Analysis failed: {str(e)}")
|
| 214 |
return None
|
| 215 |
+
|
| 216 |
+
def run_desired_outcomes_analysis():
|
| 217 |
+
handler = handlers["desired_outcome"]
|
| 218 |
+
try:
|
| 219 |
+
handler.update_info("Running Desired Outcomes Analysis...")
|
| 220 |
+
result = DesiredOutcome(os.getenv('Model_Desired_Outcomes_DM_Analyst'))
|
| 221 |
+
handler.update_success("Desired Outcomes Analysis completed successfully.")
|
| 222 |
+
return result
|
| 223 |
+
except Exception as e:
|
| 224 |
+
handler.update_error(f"Desired Outcomes Analysis failed: {str(e)}")
|
| 225 |
+
return None
|
| 226 |
|
| 227 |
def run_snapshot_analysis():
|
| 228 |
handler = handlers["snapshot"]
|
|
|
|
| 259 |
(run_sem_ppc_analysis, "sem_ppc"),
|
| 260 |
(run_marketplace_analysis, "marketplace"),
|
| 261 |
(run_target_market_analysis, "target_market"),
|
| 262 |
+
(run_df_overview_analysis, "df_overview"),
|
| 263 |
+
(run_desired_outcomes_analysis, "desired_outcome")
|
| 264 |
]
|
| 265 |
|
| 266 |
# Create and start first batch threads with small delays to prevent UI conflicts
|