Spaces:
Build error
Build error
Ronio Jerico Roque commited on
Commit ·
e24d810
1
Parent(s): b8acefa
Refactor marketplace data retrieval to separate Amazon and eBay responses; update analysis handler to use the correct model.
Browse files- classes/response_marketplace.py +5 -2
- helper/data_field.py +33 -1
- pages/analyzing_page.py +1 -1
- pages/output.py +2 -2
classes/response_marketplace.py
CHANGED
|
@@ -39,8 +39,11 @@ class Marketplace:
|
|
| 39 |
response.raise_for_status()
|
| 40 |
output = response.json()
|
| 41 |
#st.write(output)
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
#st.write(text)
|
| 45 |
return text
|
| 46 |
|
|
|
|
| 39 |
response.raise_for_status()
|
| 40 |
output = response.json()
|
| 41 |
#st.write(output)
|
| 42 |
+
text_amazon = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]["amazon"]
|
| 43 |
+
text_ebay = output["outputs"][0]["outputs"][0]["results"]["text"]["data"]["text"]["ebay"]
|
| 44 |
+
text_amazon = json.loads(text_amazon)
|
| 45 |
+
text_ebay = json.loads(text_ebay)
|
| 46 |
+
text = text_amazon + text_ebay
|
| 47 |
#st.write(text)
|
| 48 |
return text
|
| 49 |
|
helper/data_field.py
CHANGED
|
@@ -27,5 +27,37 @@ def get_analyst_response(data_src):
|
|
| 27 |
if myclient:
|
| 28 |
myclient.close()
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
|
|
|
| 27 |
if myclient:
|
| 28 |
myclient.close()
|
| 29 |
|
| 30 |
+
|
| 31 |
+
def get_marketplace_response(data_src):
|
| 32 |
+
try:
|
| 33 |
+
mongodb_uri = os.getenv("MONGODB_URI")
|
| 34 |
+
myclient = MongoClient(mongodb_uri)
|
| 35 |
+
mydb = myclient.get_database()
|
| 36 |
+
mycol = mydb["df_response"]
|
| 37 |
+
|
| 38 |
+
# Find the most recent document matching the data_src
|
| 39 |
+
document = mycol.find_one(
|
| 40 |
+
{"data_field": data_src},
|
| 41 |
+
sort=[('timestamp', -1)]
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Check if document exists and has the result field
|
| 45 |
+
if document and "result" in document:
|
| 46 |
+
# Extract amazon and ebay data separately
|
| 47 |
+
amazon_data = document["result"].get("amazon", [])
|
| 48 |
+
ebay_data = document["result"].get("ebay", [])
|
| 49 |
+
|
| 50 |
+
# Combine both datasets into a single list
|
| 51 |
+
combined_data = amazon_data + ebay_data
|
| 52 |
+
|
| 53 |
+
return combined_data
|
| 54 |
+
else:
|
| 55 |
+
print(f"No matching document or 'result' field found for data_src: {data_src} in df_response. 404")
|
| 56 |
+
return None
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"Error retrieving data: {str(e)}")
|
| 59 |
+
return None
|
| 60 |
+
finally:
|
| 61 |
+
if myclient:
|
| 62 |
+
myclient.close()
|
| 63 |
|
pages/analyzing_page.py
CHANGED
|
@@ -180,7 +180,7 @@ def run_analysis():
|
|
| 180 |
handler = handlers["marketplace"]
|
| 181 |
try:
|
| 182 |
handler.update_info("Running Marketplace Analysis...")
|
| 183 |
-
result = Marketplace(os.getenv('
|
| 184 |
handler.update_success("Marketplace Analysis completed successfully.")
|
| 185 |
return result
|
| 186 |
except Exception as e:
|
|
|
|
| 180 |
handler = handlers["marketplace"]
|
| 181 |
try:
|
| 182 |
handler.update_info("Running Marketplace Analysis...")
|
| 183 |
+
result = Marketplace(os.getenv('Model_Target_Market_Analyst'))
|
| 184 |
handler.update_success("Marketplace Analysis completed successfully.")
|
| 185 |
return result
|
| 186 |
except Exception as e:
|
pages/output.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import streamlit as st
|
| 4 |
-
from helper.data_field import get_analyst_response, data_field
|
| 5 |
import time
|
| 6 |
|
| 7 |
st.set_page_config(layout="centered")
|
|
@@ -256,7 +256,7 @@ Regardless, it is still a great channel worth investing to improve a business’
|
|
| 256 |
|
| 257 |
if (get_analyst_response("Marketplace Analyst")):
|
| 258 |
st.markdown("### MARKET PLACE")
|
| 259 |
-
marketpalce_data =
|
| 260 |
write_table(marketpalce_data)
|
| 261 |
st.markdown("<a href='#top'>Go to top</a>", unsafe_allow_html=True)
|
| 262 |
st.markdown("---")
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import streamlit as st
|
| 4 |
+
from helper.data_field import get_analyst_response, data_field, get_marketplace_response
|
| 5 |
import time
|
| 6 |
|
| 7 |
st.set_page_config(layout="centered")
|
|
|
|
| 256 |
|
| 257 |
if (get_analyst_response("Marketplace Analyst")):
|
| 258 |
st.markdown("### MARKET PLACE")
|
| 259 |
+
marketpalce_data = get_marketplace_response("Marketplace Analyst")
|
| 260 |
write_table(marketpalce_data)
|
| 261 |
st.markdown("<a href='#top'>Go to top</a>", unsafe_allow_html=True)
|
| 262 |
st.markdown("---")
|