Spaces:
Running
Running
Sigrid De los Santos
commited on
Commit
Β·
1353a1f
1
Parent(s):
7cb8f2e
debugging for analysis tables
Browse files- app.py +7 -1
- src/main.py +11 -9
app.py
CHANGED
@@ -34,7 +34,7 @@ with st.form("topics_form"):
|
|
34 |
submitted = st.form_submit_button("Run Analysis")
|
35 |
|
36 |
# === Tabs Setup ===
|
37 |
-
tab_report, tab_articles, tab_insights = st.tabs(["π Report", "π Articles", "π Insights"])
|
38 |
|
39 |
if submitted:
|
40 |
if not openai_api_key or not tavily_api_key or not all([td['topic'] for td in topics_data]):
|
@@ -137,10 +137,16 @@ if submitted:
|
|
137 |
)
|
138 |
else:
|
139 |
st.info("No insights available.")
|
|
|
|
|
|
|
140 |
|
141 |
except Exception as e:
|
142 |
spinner_box.error("β Failed.")
|
143 |
log_box.error(f"β Error: {e}")
|
|
|
|
|
|
|
144 |
|
145 |
# import os
|
146 |
# import sys
|
|
|
34 |
submitted = st.form_submit_button("Run Analysis")
|
35 |
|
36 |
# === Tabs Setup ===
|
37 |
+
tab_report, tab_articles, tab_insights, tab_debug = st.tabs(["π Report", "π Articles", "π Insights", "π Debug"])
|
38 |
|
39 |
if submitted:
|
40 |
if not openai_api_key or not tavily_api_key or not all([td['topic'] for td in topics_data]):
|
|
|
137 |
)
|
138 |
else:
|
139 |
st.info("No insights available.")
|
140 |
+
with tab_debug:
|
141 |
+
st.subheader("π Debug Log")
|
142 |
+
st.code("\n".join(logs) if logs else "No logs yet.")
|
143 |
|
144 |
except Exception as e:
|
145 |
spinner_box.error("β Failed.")
|
146 |
log_box.error(f"β Error: {e}")
|
147 |
+
# === Debug Tab ===
|
148 |
+
|
149 |
+
|
150 |
|
151 |
# import os
|
152 |
# import sys
|
src/main.py
CHANGED
@@ -38,7 +38,15 @@ def run_value_investing_analysis(csv_path, progress_callback=None):
|
|
38 |
if progress_callback:
|
39 |
progress_callback(f"π Processing topic: {topic} ({timespan} days)")
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
if not news:
|
43 |
if progress_callback:
|
44 |
progress_callback(f"β οΈ No news found for topic: {topic}")
|
@@ -50,7 +58,6 @@ def run_value_investing_analysis(csv_path, progress_callback=None):
|
|
50 |
url = article.get("url", "")
|
51 |
date = article.get("date", datetime.now().strftime("%Y-%m-%d"))
|
52 |
|
53 |
-
# === Sentiment Analysis ===
|
54 |
try:
|
55 |
result = analyze_article(summary)
|
56 |
sentiment = result.get("sentiment", "Neutral")
|
@@ -75,13 +82,12 @@ def run_value_investing_analysis(csv_path, progress_callback=None):
|
|
75 |
})
|
76 |
|
77 |
company_data.append({
|
78 |
-
"Company": topic,
|
79 |
"Sentiment": sentiment,
|
80 |
"Confidence": confidence,
|
81 |
"Summary": summary,
|
82 |
})
|
83 |
|
84 |
-
# Save markdown report
|
85 |
try:
|
86 |
report_body = generate_value_investor_report(topic, news)
|
87 |
filename = f"{topic.replace(' ', '_').lower()}_{datetime.now().strftime('%Y-%m-%d')}.md"
|
@@ -113,16 +119,13 @@ def build_company_insights(company_data):
|
|
113 |
"Confidence": avg_confidence,
|
114 |
"Highlights": highlights
|
115 |
})
|
116 |
-
|
117 |
-
insights_df = pd.DataFrame(insights)
|
118 |
-
return insights_df.sort_values(by="Confidence", ascending=False).head(5)
|
119 |
|
120 |
# === Pipeline ===
|
121 |
def run_pipeline(csv_path, tavily_api_key, progress_callback=None):
|
122 |
os.environ["TAVILY_API_KEY"] = tavily_api_key
|
123 |
all_articles, company_data = run_value_investing_analysis(csv_path, progress_callback)
|
124 |
|
125 |
-
# Convert markdown to HTML
|
126 |
html_paths = []
|
127 |
for md_file in os.listdir(DATA_DIR):
|
128 |
if md_file.endswith(".md"):
|
@@ -133,7 +136,6 @@ def run_pipeline(csv_path, tavily_api_key, progress_callback=None):
|
|
133 |
insights_df = build_company_insights(company_data)
|
134 |
return html_paths, articles_df, insights_df
|
135 |
|
136 |
-
|
137 |
# import os
|
138 |
# import pandas as pd
|
139 |
# from datetime import datetime
|
|
|
38 |
if progress_callback:
|
39 |
progress_callback(f"π Processing topic: {topic} ({timespan} days)")
|
40 |
|
41 |
+
try:
|
42 |
+
news = fetch_deep_news(topic, timespan)
|
43 |
+
if progress_callback:
|
44 |
+
progress_callback(f"[DEBUG] fetch_deep_news returned {len(news) if news else 0} articles.")
|
45 |
+
except Exception as e:
|
46 |
+
if progress_callback:
|
47 |
+
progress_callback(f"[ERROR] fetch_deep_news failed: {e}")
|
48 |
+
continue
|
49 |
+
|
50 |
if not news:
|
51 |
if progress_callback:
|
52 |
progress_callback(f"β οΈ No news found for topic: {topic}")
|
|
|
58 |
url = article.get("url", "")
|
59 |
date = article.get("date", datetime.now().strftime("%Y-%m-%d"))
|
60 |
|
|
|
61 |
try:
|
62 |
result = analyze_article(summary)
|
63 |
sentiment = result.get("sentiment", "Neutral")
|
|
|
82 |
})
|
83 |
|
84 |
company_data.append({
|
85 |
+
"Company": topic,
|
86 |
"Sentiment": sentiment,
|
87 |
"Confidence": confidence,
|
88 |
"Summary": summary,
|
89 |
})
|
90 |
|
|
|
91 |
try:
|
92 |
report_body = generate_value_investor_report(topic, news)
|
93 |
filename = f"{topic.replace(' ', '_').lower()}_{datetime.now().strftime('%Y-%m-%d')}.md"
|
|
|
119 |
"Confidence": avg_confidence,
|
120 |
"Highlights": highlights
|
121 |
})
|
122 |
+
return pd.DataFrame(insights).sort_values(by="Confidence", ascending=False).head(5)
|
|
|
|
|
123 |
|
124 |
# === Pipeline ===
|
125 |
def run_pipeline(csv_path, tavily_api_key, progress_callback=None):
|
126 |
os.environ["TAVILY_API_KEY"] = tavily_api_key
|
127 |
all_articles, company_data = run_value_investing_analysis(csv_path, progress_callback)
|
128 |
|
|
|
129 |
html_paths = []
|
130 |
for md_file in os.listdir(DATA_DIR):
|
131 |
if md_file.endswith(".md"):
|
|
|
136 |
insights_df = build_company_insights(company_data)
|
137 |
return html_paths, articles_df, insights_df
|
138 |
|
|
|
139 |
# import os
|
140 |
# import pandas as pd
|
141 |
# from datetime import datetime
|