Spaces:
Sleeping
Sleeping
Commit
·
96f9491
1
Parent(s):
f2ba8f4
check
Browse files
app.py
CHANGED
@@ -1,24 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
else:
|
14 |
-
return "
|
15 |
|
|
|
16 |
iface = gr.Interface(
|
17 |
-
fn=
|
18 |
-
inputs=gr.
|
19 |
-
outputs="
|
20 |
-
title="
|
21 |
-
description="
|
22 |
)
|
23 |
|
24 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
# Alpha Vantage API key
|
6 |
+
API_KEY = "PJRAUD6KHJ2O097X"
|
7 |
+
|
8 |
+
# Function to fetch stock data
|
9 |
+
def get_stock_data(symbol):
|
10 |
+
url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={symbol}&apikey={API_KEY}"
|
11 |
+
response = requests.get(url)
|
12 |
+
data = response.json()
|
13 |
+
|
14 |
+
if "Time Series (Daily)" in data:
|
15 |
+
df = pd.DataFrame(data["Time Series (Daily)"]).T
|
16 |
+
df.columns = ["Open", "High", "Low", "Close", "Volume"]
|
17 |
+
return df.head().to_html() # Display the latest 5 days of data
|
18 |
else:
|
19 |
+
return "Data not found or invalid stock symbol."
|
20 |
|
21 |
+
# Gradio app interface
|
22 |
iface = gr.Interface(
|
23 |
+
fn=get_stock_data,
|
24 |
+
inputs=gr.Textbox(label="Stock Symbol", placeholder="Enter a stock symbol (like AAPL, MSFT)"),
|
25 |
+
outputs="html",
|
26 |
+
title="Stock Market Data App",
|
27 |
+
description="Enter a stock symbol to fetch its daily time series data."
|
28 |
)
|
29 |
|
30 |
if __name__ == "__main__":
|