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()