Spaces:
Sleeping
Sleeping
Commit
·
cf2068c
1
Parent(s):
fecb358
app.py: prettify output
Browse files
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from src.stock_analysis_agent import StockAnalyst
|
| 3 |
|
| 4 |
|
|
@@ -17,8 +19,26 @@ def interact_with_agent(agent_instance, ticker):
|
|
| 17 |
if agent_instance is None:
|
| 18 |
return 'Stock-Analysis Agent is not initialized. Please initialize first.'
|
| 19 |
messages = agent_instance.get_stock_suggestion(ticker)
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
gr.Markdown("# Stock Analysis Agent")
|
|
@@ -36,7 +56,7 @@ with gr.Blocks() as demo:
|
|
| 36 |
gr.Markdown("Enter a stock symbol ('ticker') to be analyzed (GOOG, MSFT, etc.)")
|
| 37 |
ticker = gr.Textbox(label="ticker")
|
| 38 |
analyze_button = gr.Button('Analyze Stock')
|
| 39 |
-
output = gr.
|
| 40 |
analyze_button.click(
|
| 41 |
fn=interact_with_agent,
|
| 42 |
inputs=[agent_instance, ticker],
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
from src.stock_analysis_agent import StockAnalyst
|
| 5 |
|
| 6 |
|
|
|
|
| 19 |
if agent_instance is None:
|
| 20 |
return 'Stock-Analysis Agent is not initialized. Please initialize first.'
|
| 21 |
messages = agent_instance.get_stock_suggestion(ticker)
|
| 22 |
+
FA_str = messages[-2].model_dump()['content']
|
| 23 |
+
summary_str = messages[-1].model_dump()['content']
|
| 24 |
+
response_pretty = ''
|
| 25 |
+
try:
|
| 26 |
+
FA_dict = json.loads(FA_str)
|
| 27 |
+
response_pretty += f"**Company Name:** {FA_dict['Company Name']} \n"
|
| 28 |
+
response_pretty += f"**Sector:** {FA_dict['Sector']}\n\n"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
response_pretty += f"**ticker**: {ticker}\n\n"
|
| 31 |
+
print(f'Error parsing the Financial Analysis response:\n{e}')
|
| 32 |
+
try:
|
| 33 |
+
summary_dict = json.loads(summary_str)
|
| 34 |
+
for key, value in summary_dict.items():
|
| 35 |
+
if key != 'stock':
|
| 36 |
+
pretty_key = key.replace('_', ' ').title()
|
| 37 |
+
response_pretty += f"**{pretty_key}**: {value}\n\n"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
response_pretty += f'*An error occured stylizing the response, printing the raw response*:\n{summary_str}'
|
| 40 |
+
print(f'Error parsing summary response:\n{e}\n')
|
| 41 |
+
return response_pretty
|
| 42 |
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.Markdown("# Stock Analysis Agent")
|
|
|
|
| 56 |
gr.Markdown("Enter a stock symbol ('ticker') to be analyzed (GOOG, MSFT, etc.)")
|
| 57 |
ticker = gr.Textbox(label="ticker")
|
| 58 |
analyze_button = gr.Button('Analyze Stock')
|
| 59 |
+
output = gr.Markdown(label="Output Box")
|
| 60 |
analyze_button.click(
|
| 61 |
fn=interact_with_agent,
|
| 62 |
inputs=[agent_instance, ticker],
|