CCockrum commited on
Commit
8beaa28
·
verified ·
1 Parent(s): b766c67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -18,9 +18,6 @@ headers = {
18
  "Authorization": f"Bearer {HF_TOKEN}"
19
  }
20
 
21
- # Load summarizer model
22
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
23
-
24
  # Function to query Mistral API
25
  def query_mistral(question):
26
  payload = {
@@ -42,6 +39,23 @@ sector_averages = {
42
  "Energy": {"P/E Ratio": 12, "P/S Ratio": 1.2, "P/B Ratio": 1.3},
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Safe Request Function
46
  def safe_request(url):
47
  try:
@@ -191,7 +205,9 @@ def stock_research(symbol, eps=5.0, growth=0.1, book=500000000):
191
  return summary, info_table, ratios_table, sector_comp, fig
192
 
193
  # Gradio UI
194
- with gr.Blocks(theme="soft") as iface:
 
 
195
  with gr.Row():
196
  symbol = gr.Textbox(label="Stock Symbol (e.g., AAPL)")
197
  eps = gr.Number(label="Assumed EPS", value=5.0)
@@ -213,7 +229,15 @@ with gr.Blocks(theme="soft") as iface:
213
  user_question = gr.Textbox(label="Ask about investing...")
214
  answer_box = gr.Textbox(label="Answer")
215
  ask_button = gr.Button("Get Answer")
216
- ask_button.click(fn=query_mistral, inputs=[user_question], outputs=[answer_box])
 
 
 
 
 
 
 
 
217
 
218
  submit_btn = gr.Button("Run Analysis")
219
  download_btn = gr.Button("Download Report")
@@ -222,5 +246,6 @@ with gr.Blocks(theme="soft") as iface:
222
  submit_btn.click(fn=stock_research, inputs=[symbol, eps, growth, book],
223
  outputs=[output_summary, output_info, output_ratios, output_sector, output_chart])
224
 
 
225
  if __name__ == "__main__":
226
  iface.launch()
 
18
  "Authorization": f"Bearer {HF_TOKEN}"
19
  }
20
 
 
 
 
21
  # Function to query Mistral API
22
  def query_mistral(question):
23
  payload = {
 
39
  "Energy": {"P/E Ratio": 12, "P/S Ratio": 1.2, "P/B Ratio": 1.3},
40
  }
41
 
42
+ # Safe Request Function
43
+ def safe_request(url):
44
+ try:
45
+ response = requests.get(url)
46
+ response.raise_for_status()
47
+ return response
48
+ except:
49
+ return None
50
+
51
+ # Fetch Functions
52
+ # (functions unchanged)
53
+ # ...
54
+
55
+ # Financial Calculations
56
+ # (functions unchanged)
57
+ # ...
58
+
59
  # Safe Request Function
60
  def safe_request(url):
61
  try:
 
205
  return summary, info_table, ratios_table, sector_comp, fig
206
 
207
  # Gradio UI
208
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as iface:
209
+ theme_choice = gr.Radio(choices=["light", "dark"], value="light", label="Choose Theme")
210
+
211
  with gr.Row():
212
  symbol = gr.Textbox(label="Stock Symbol (e.g., AAPL)")
213
  eps = gr.Number(label="Assumed EPS", value=5.0)
 
229
  user_question = gr.Textbox(label="Ask about investing...")
230
  answer_box = gr.Textbox(label="Answer")
231
  ask_button = gr.Button("Get Answer")
232
+ with gr.Row():
233
+ ask_button.click(fn=lambda q: query_mistral(q),
234
+ inputs=[user_question],
235
+ outputs=[answer_box],
236
+ api_name="query_mistral").then(
237
+ lambda: "",
238
+ inputs=[],
239
+ outputs=[user_question]
240
+ )
241
 
242
  submit_btn = gr.Button("Run Analysis")
243
  download_btn = gr.Button("Download Report")
 
246
  submit_btn.click(fn=stock_research, inputs=[symbol, eps, growth, book],
247
  outputs=[output_summary, output_info, output_ratios, output_sector, output_chart])
248
 
249
+
250
  if __name__ == "__main__":
251
  iface.launch()