Poojashetty357 commited on
Commit
080f8ad
Β·
verified Β·
1 Parent(s): 9207e62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -135,36 +135,35 @@ def stock_insight(company_name):
135
  global chart_data
136
  symbol = get_stock_symbol(company_name)
137
  if not symbol:
138
- return f"❌ Could not find stock symbol for '{company_name}'.", "", "", "", "", ""
139
 
140
  price, last_trade = get_stock_quote(symbol)
141
  if not price:
142
- return f"❌ Could not fetch price for symbol {symbol}.", "", "", "", "", ""
143
 
144
  overview = get_financial_overview(symbol)
145
  if not overview:
146
- return f"❌ Could not fetch financial data for {symbol}.", "", "", "", "", ""
147
 
148
  chart_data = overview # Store for later chart use
149
  summary = ask_gpt_summary(company_name, overview)
150
 
151
- return (
152
- f"βœ… Symbol: {symbol}",
153
- f"πŸ’² Price: ${price}",
154
- f"πŸ—“οΈ Last Trading Day: {last_trade}",
155
- f"πŸ“Š P/E Ratio: {overview['P/E Ratio']}\nEPS: {overview['EPS']}\nMarket Cap: ${overview['Market Cap']}",
156
- f"πŸ“ Company Summary: {overview['Description'][:300]}...",
157
- f"πŸ€– GPT Insight: {summary}",
158
- overview # return chart_data for use in next function
159
  )
160
-
161
  # 🎨 Chart render on button click
162
  def generate_chart(chart_data_input):
163
  if chart_data_input:
164
  return plot_financials(chart_data_input)
165
  return None
166
 
167
-
168
  # πŸ–₯️ Gradio UI
169
  with gr.Blocks() as demo:
170
  gr.Markdown("# πŸ“ˆ Stock Market Assistant")
@@ -194,11 +193,10 @@ with gr.Blocks() as demo:
194
  outputs=[
195
  symbol_output, price_output, trade_output,
196
  financial_output, company_summary, gpt_output,
197
- chart_data_state # store chart data
198
  ]
199
  )
200
 
201
  generate_chart_button.click(generate_chart, inputs=chart_data_state, outputs=chart_output)
202
 
203
-
204
- demo.launch()
 
135
  global chart_data
136
  symbol = get_stock_symbol(company_name)
137
  if not symbol:
138
+ return f"❌ Could not find stock symbol for '{company_name}'.", "", "", "", "", "", ""
139
 
140
  price, last_trade = get_stock_quote(symbol)
141
  if not price:
142
+ return f"❌ Could not fetch price for symbol {symbol}.", "", "", "", "", "", ""
143
 
144
  overview = get_financial_overview(symbol)
145
  if not overview:
146
+ return f"❌ Could not fetch financial data for {symbol}.", "", "", "", "", "", ""
147
 
148
  chart_data = overview # Store for later chart use
149
  summary = ask_gpt_summary(company_name, overview)
150
 
151
+ return (
152
+ f"βœ… Symbol: {symbol}",
153
+ f"πŸ’² Price: ${price}",
154
+ f"πŸ—“οΈ Last Trading Day: {last_trade}",
155
+ f"πŸ“Š P/E Ratio: {overview['P/E Ratio']}\nEPS: {overview['EPS']}\nMarket Cap: ${overview['Market Cap']}",
156
+ f"πŸ“ Company Summary: {overview['Description'][:300]}...",
157
+ f"πŸ€– GPT Insight: {summary}",
158
+ overview
159
  )
160
+
161
  # 🎨 Chart render on button click
162
  def generate_chart(chart_data_input):
163
  if chart_data_input:
164
  return plot_financials(chart_data_input)
165
  return None
166
 
 
167
  # πŸ–₯️ Gradio UI
168
  with gr.Blocks() as demo:
169
  gr.Markdown("# πŸ“ˆ Stock Market Assistant")
 
193
  outputs=[
194
  symbol_output, price_output, trade_output,
195
  financial_output, company_summary, gpt_output,
196
+ chart_data_state
197
  ]
198
  )
199
 
200
  generate_chart_button.click(generate_chart, inputs=chart_data_state, outputs=chart_output)
201
 
202
+ demo.launch()