Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,19 +3,22 @@ import gradio as gr
|
|
3 |
|
4 |
# Function to fetch and return data for a given ticker symbol
|
5 |
def fetch_stock_data(ticker_symbol):
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
|
|
|
|
19 |
|
20 |
# Gradio interface
|
21 |
def create_gradio_interface():
|
@@ -24,14 +27,13 @@ def create_gradio_interface():
|
|
24 |
historical_output = gr.Dataframe(label="Historical Data (1 Year)")
|
25 |
financials_output = gr.Dataframe(label="Financials")
|
26 |
actions_output = gr.Dataframe(label="Stock Actions")
|
27 |
-
submit_button = gr.Button("Submit")
|
28 |
|
29 |
# Define the Gradio interface with explicit submit button
|
30 |
interface = gr.Interface(
|
31 |
fn=fetch_stock_data,
|
32 |
-
inputs=
|
33 |
outputs=[historical_output, financials_output, actions_output],
|
34 |
-
live=False, # Disable live updates
|
35 |
title="Stock Data Fetcher",
|
36 |
description="Enter a ticker symbol and click 'Submit' to fetch historical data, financials, and stock actions."
|
37 |
)
|
|
|
3 |
|
4 |
# Function to fetch and return data for a given ticker symbol
|
5 |
def fetch_stock_data(ticker_symbol):
|
6 |
+
try:
|
7 |
+
# Create a Ticker object
|
8 |
+
ticker = yf.Ticker(ticker_symbol)
|
9 |
|
10 |
+
# Fetch historical market data
|
11 |
+
historical_data = ticker.history(period="1y") # data for the last year
|
12 |
|
13 |
+
# Fetch basic financials
|
14 |
+
financials = ticker.financials
|
15 |
|
16 |
+
# Fetch stock actions like dividends and splits
|
17 |
+
actions = ticker.actions
|
18 |
|
19 |
+
return historical_data, financials, actions
|
20 |
+
except Exception as e:
|
21 |
+
return f"Error: {e}", None, None
|
22 |
|
23 |
# Gradio interface
|
24 |
def create_gradio_interface():
|
|
|
27 |
historical_output = gr.Dataframe(label="Historical Data (1 Year)")
|
28 |
financials_output = gr.Dataframe(label="Financials")
|
29 |
actions_output = gr.Dataframe(label="Stock Actions")
|
|
|
30 |
|
31 |
# Define the Gradio interface with explicit submit button
|
32 |
interface = gr.Interface(
|
33 |
fn=fetch_stock_data,
|
34 |
+
inputs=ticker_input,
|
35 |
outputs=[historical_output, financials_output, actions_output],
|
36 |
+
live=False, # Disable live updates to avoid the interface from triggering automatically
|
37 |
title="Stock Data Fetcher",
|
38 |
description="Enter a ticker symbol and click 'Submit' to fetch historical data, financials, and stock actions."
|
39 |
)
|