Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,20 @@ import datetime
|
|
7 |
import tempfile
|
8 |
from transformers import pipeline
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
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")
|