CCockrum commited on
Commit
e314039
·
verified ·
1 Parent(s): ad9f8c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -7,9 +7,20 @@ import datetime
7
  import tempfile
8
  from transformers import pipeline
9
 
10
- # Initialize Summarizer and Chat Model
11
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
12
- chat_model = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", max_length=256)
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # API Key
15
  POLYGON_API_KEY = os.getenv("POLYGON_API_KEY")
@@ -195,9 +206,11 @@ with gr.Blocks(theme="soft") as iface:
195
  output_chart = gr.Plot()
196
  with gr.Tab("Ask About Investing"):
197
  user_question = gr.Textbox(label="Ask about investing...")
198
- answer_box = gr.Textbox()
 
199
  ask_button = gr.Button("Get Answer")
200
- ask_button.click(fn=answer_investing_question, inputs=[user_question], outputs=[answer_box])
 
201
 
202
  submit_btn = gr.Button("Run Analysis")
203
  download_btn = gr.Button("Download Report")
 
7
  import tempfile
8
  from transformers import pipeline
9
 
10
+
11
+ # Lightweight model for quick answers
12
+ light_chat_model = pipeline("text-generation", model="google/flan-t5-small", max_length=256)
13
+
14
+ # Heavier model for advanced summarization
15
+ advanced_summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
16
+
17
+ def answer_investing_question(question, level="basic"):
18
+ if level == "basic":
19
+ response = light_chat_model(question)[0]['generated_text']
20
+ else:
21
+ prompt = f"Explain in detail: {question}"
22
+ response = advanced_summarizer(prompt, max_length=250, min_length=100, do_sample=False)[0]['summary_text']
23
+ return response.strip()
24
 
25
  # API Key
26
  POLYGON_API_KEY = os.getenv("POLYGON_API_KEY")
 
206
  output_chart = gr.Plot()
207
  with gr.Tab("Ask About Investing"):
208
  user_question = gr.Textbox(label="Ask about investing...")
209
+ level = gr.Dropdown(choices=["basic", "advanced"], value="basic", label="Answer Detail Level")
210
+ answer_box = gr.Textbox(label="Answer")
211
  ask_button = gr.Button("Get Answer")
212
+ ask_button.click(fn=answer_investing_question, inputs=[user_question, level], outputs=[answer_box])
213
+
214
 
215
  submit_btn = gr.Button("Run Analysis")
216
  download_btn = gr.Button("Download Report")