Method314 commited on
Commit
a779d49
·
verified ·
1 Parent(s): 716866e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -184,6 +184,9 @@ def plot_candlestick_chart(data, ticker):
184
  return fig, current_price, None, None
185
 
186
  def format_price_info(current_price, log_price, percent_diff):
 
 
 
187
  if log_price is None or percent_diff is None:
188
  return f"Current Price: ${current_price:.2f}"
189
 
@@ -219,7 +222,7 @@ custom_css = """
219
  }
220
  """
221
 
222
- # Create Gradio interface with custom Seafoam theme
223
  with gr.Blocks(theme=seafoam, title="Stock Charts", css=custom_css) as iface:
224
  gr.Markdown("# Stock Charts")
225
  gr.Markdown("Enter a stock ticker and date range to generate a chart.")
@@ -239,14 +242,15 @@ with gr.Blocks(theme=seafoam, title="Stock Charts", css=custom_css) as iface:
239
 
240
  price_info = gr.HTML(label="Price Information")
241
 
 
 
 
 
 
242
  submit_button.click(
243
- plot_chart,
244
  inputs=[ticker, start_date, end_date, chart_type],
245
  outputs=[chart, price_info]
246
- ).then(
247
- lambda current_price, log_price, percent_diff: format_price_info(current_price, log_price, percent_diff),
248
- inputs=[gr.State(None), gr.State(None), gr.State(None)],
249
- outputs=[price_info]
250
  )
251
 
252
  # Launch the app
 
184
  return fig, current_price, None, None
185
 
186
  def format_price_info(current_price, log_price, percent_diff):
187
+ if current_price is None:
188
+ return "Unable to retrieve price information."
189
+
190
  if log_price is None or percent_diff is None:
191
  return f"Current Price: ${current_price:.2f}"
192
 
 
222
  }
223
  """
224
 
225
+ # Update the Gradio interface section
226
  with gr.Blocks(theme=seafoam, title="Stock Charts", css=custom_css) as iface:
227
  gr.Markdown("# Stock Charts")
228
  gr.Markdown("Enter a stock ticker and date range to generate a chart.")
 
242
 
243
  price_info = gr.HTML(label="Price Information")
244
 
245
+ def update_chart_and_info(ticker, start_date, end_date, chart_type):
246
+ chart_data, current_price, log_price, percent_diff = plot_chart(ticker, start_date, end_date, chart_type)
247
+ price_info_html = format_price_info(current_price, log_price, percent_diff)
248
+ return chart_data, price_info_html
249
+
250
  submit_button.click(
251
+ update_chart_and_info,
252
  inputs=[ticker, start_date, end_date, chart_type],
253
  outputs=[chart, price_info]
 
 
 
 
254
  )
255
 
256
  # Launch the app