File size: 984 Bytes
63495b1
96f9491
 
f2ba8f4
96f9491
 
 
 
 
 
 
 
 
 
 
 
 
f2ba8f4
96f9491
63495b1
96f9491
63495b1
96f9491
 
 
 
 
63495b1
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
import requests
import pandas as pd

# Alpha Vantage API key
API_KEY = "PJRAUD6KHJ2O097X"

# Function to fetch stock data
def get_stock_data(symbol):
    url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={symbol}&apikey={API_KEY}"
    response = requests.get(url)
    data = response.json()

    if "Time Series (Daily)" in data:
        df = pd.DataFrame(data["Time Series (Daily)"]).T
        df.columns = ["Open", "High", "Low", "Close", "Volume"]
        return df.head().to_html()  # Display the latest 5 days of data
    else:
        return "Data not found or invalid stock symbol."

# Gradio app interface
iface = gr.Interface(
    fn=get_stock_data,
    inputs=gr.Textbox(label="Stock Symbol", placeholder="Enter a stock symbol (like AAPL, MSFT)"),
    outputs="html",
    title="Stock Market Data App",
    description="Enter a stock symbol to fetch its daily time series data."
)

if __name__ == "__main__":
    iface.launch()