Sigrid De los Santos commited on
Commit
7d2254a
Β·
1 Parent(s): 7a4bde2

Add matplotlib to requirements

Browse files
Files changed (1) hide show
  1. app.py +44 -13
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 so we can import main.py
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
- progress_box = st.empty()
 
 
 
 
55
  rotating = True
 
 
 
 
 
56
 
57
  def rotating_messages():
58
  messages = itertools.cycle([
59
- "πŸ” Searching financial news sources...",
60
- "🧠 Running language model analysis...",
61
- "πŸ“Š Generating investment reports..."
 
 
62
  ])
63
  while rotating:
64
- progress_box.markdown(f"⏳ {next(messages)}")
65
- time.sleep(1.5)
66
 
67
  rotator_thread = Thread(target=rotating_messages)
68
  rotator_thread.start()
69
 
70
  try:
71
- output_path = run_pipeline(csv_path, tavily_api_key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  rotating = False
73
  rotator_thread.join()
74
- progress_box.success("βœ… Analysis complete!")
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
- progress_box.error(f"❌ Error: {e}")
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
  ##################################################################################################