Spaces:
Runtime error
Runtime error
Sigrid De los Santos
commited on
Commit
Β·
7d2254a
1
Parent(s):
7a4bde2
Add matplotlib to requirements
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import tempfile
|
|
@@ -6,10 +5,10 @@ import time
|
|
| 6 |
import itertools
|
| 7 |
import streamlit as st
|
| 8 |
import pandas as pd
|
| 9 |
-
from io import StringIO
|
| 10 |
from threading import Thread
|
|
|
|
| 11 |
|
| 12 |
-
# Add 'src' to Python path
|
| 13 |
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 14 |
from main import run_pipeline
|
| 15 |
|
|
@@ -51,27 +50,59 @@ if submitted:
|
|
| 51 |
df.to_csv(tmp_csv.name, index=False)
|
| 52 |
csv_path = tmp_csv.name
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
rotating = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
def rotating_messages():
|
| 58 |
messages = itertools.cycle([
|
| 59 |
-
"π Searching financial news
|
| 60 |
-
"π§ Running language
|
| 61 |
-
"π Generating investment reports..."
|
|
|
|
|
|
|
| 62 |
])
|
| 63 |
while rotating:
|
| 64 |
-
|
| 65 |
-
time.sleep(1.
|
| 66 |
|
| 67 |
rotator_thread = Thread(target=rotating_messages)
|
| 68 |
rotator_thread.start()
|
| 69 |
|
| 70 |
try:
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
rotating = False
|
| 73 |
rotator_thread.join()
|
| 74 |
-
|
| 75 |
|
| 76 |
if output_path and isinstance(output_path, list):
|
| 77 |
for path in output_path:
|
|
@@ -93,8 +124,8 @@ if submitted:
|
|
| 93 |
except Exception as e:
|
| 94 |
rotating = False
|
| 95 |
rotator_thread.join()
|
| 96 |
-
|
| 97 |
-
|
| 98 |
|
| 99 |
##################################################################################################
|
| 100 |
##################################################################################################
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import tempfile
|
|
|
|
| 5 |
import itertools
|
| 6 |
import streamlit as st
|
| 7 |
import pandas as pd
|
|
|
|
| 8 |
from threading import Thread
|
| 9 |
+
from io import StringIO
|
| 10 |
|
| 11 |
+
# Add 'src' to Python path
|
| 12 |
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 13 |
from main import run_pipeline
|
| 14 |
|
|
|
|
| 50 |
df.to_csv(tmp_csv.name, index=False)
|
| 51 |
csv_path = tmp_csv.name
|
| 52 |
|
| 53 |
+
# Placeholders
|
| 54 |
+
spinner_box = st.empty()
|
| 55 |
+
log_box = st.empty()
|
| 56 |
+
|
| 57 |
+
# Rotating spinner text
|
| 58 |
rotating = True
|
| 59 |
+
logs = []
|
| 60 |
+
|
| 61 |
+
def log(msg):
|
| 62 |
+
logs.append(msg)
|
| 63 |
+
log_box.code("\n".join(logs))
|
| 64 |
|
| 65 |
def rotating_messages():
|
| 66 |
messages = itertools.cycle([
|
| 67 |
+
"π Searching financial news...",
|
| 68 |
+
"π§ Running language models...",
|
| 69 |
+
"π Generating investment reports...",
|
| 70 |
+
"π Compiling markdown...",
|
| 71 |
+
"π Looking for value signals..."
|
| 72 |
])
|
| 73 |
while rotating:
|
| 74 |
+
spinner_box.markdown(f"β³ {next(messages)}")
|
| 75 |
+
time.sleep(1.4)
|
| 76 |
|
| 77 |
rotator_thread = Thread(target=rotating_messages)
|
| 78 |
rotator_thread.start()
|
| 79 |
|
| 80 |
try:
|
| 81 |
+
# Log: API checks
|
| 82 |
+
log("π Checking API keys...")
|
| 83 |
+
import openai
|
| 84 |
+
openai_client = openai.OpenAI(api_key=openai_api_key)
|
| 85 |
+
openai_client.models.list() # triggers check
|
| 86 |
+
log("β
OpenAI API key is valid.")
|
| 87 |
+
|
| 88 |
+
import requests
|
| 89 |
+
tavily_check = requests.post(
|
| 90 |
+
"https://api.tavily.com/search",
|
| 91 |
+
headers={"Authorization": f"Bearer {tavily_api_key}"},
|
| 92 |
+
json={"query": "test", "days": 1, "max_results": 1}
|
| 93 |
+
)
|
| 94 |
+
if tavily_check.status_code == 200:
|
| 95 |
+
log("β
Tavily API key is valid.")
|
| 96 |
+
else:
|
| 97 |
+
raise ValueError(f"Tavily key failed: {tavily_check.status_code} - {tavily_check.text}")
|
| 98 |
+
|
| 99 |
+
# Run main pipeline
|
| 100 |
+
log("π Running analysis pipeline...")
|
| 101 |
+
output_path = run_pipeline(csv_path, tavily_api_key, progress_callback=log)
|
| 102 |
+
|
| 103 |
rotating = False
|
| 104 |
rotator_thread.join()
|
| 105 |
+
spinner_box.success("β
Analysis complete!")
|
| 106 |
|
| 107 |
if output_path and isinstance(output_path, list):
|
| 108 |
for path in output_path:
|
|
|
|
| 124 |
except Exception as e:
|
| 125 |
rotating = False
|
| 126 |
rotator_thread.join()
|
| 127 |
+
spinner_box.error("β Failed.")
|
| 128 |
+
log_box.error(f"β Error: {e}")
|
| 129 |
|
| 130 |
##################################################################################################
|
| 131 |
##################################################################################################
|