Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,42 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import yfinance as yf
|
2 |
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 |
+
# Create a Ticker object
|
7 |
+
ticker = yf.Ticker(ticker_symbol)
|
8 |
+
|
9 |
+
# Fetch historical market data
|
10 |
+
historical_data = ticker.history(period="1y") # data for the last year
|
11 |
+
|
12 |
+
# Fetch basic financials
|
13 |
+
financials = ticker.financials
|
14 |
+
|
15 |
+
# Fetch stock actions like dividends and splits
|
16 |
+
actions = ticker.actions
|
17 |
+
|
18 |
+
return historical_data, financials, actions
|
19 |
+
|
20 |
+
# Gradio interface
|
21 |
+
def create_gradio_interface():
|
22 |
+
# Define the input and output for Gradio
|
23 |
+
ticker_input = gr.inputs.Textbox(label="Enter Ticker Symbol")
|
24 |
+
historical_output = gr.outputs.Dataframe(label="Historical Data (1 Year)")
|
25 |
+
financials_output = gr.outputs.Dataframe(label="Financials")
|
26 |
+
actions_output = gr.outputs.Dataframe(label="Stock Actions")
|
27 |
+
|
28 |
+
# Define the Gradio interface
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=fetch_stock_data,
|
31 |
+
inputs=ticker_input,
|
32 |
+
outputs=[historical_output, financials_output, actions_output],
|
33 |
+
live=True,
|
34 |
+
title="Stock Data Fetcher",
|
35 |
+
description="Enter a ticker symbol to fetch historical data, financials, and stock actions."
|
36 |
+
)
|
37 |
+
|
38 |
+
# Launch the interface
|
39 |
+
interface.launch()
|
40 |
+
|
41 |
+
# Run the Gradio interface
|
42 |
+
create_gradio_interface()
|