import streamlit as st import requests import pandas as pd # Hard-coded API key for demonstration purposes API_KEY = "QR8F9B7T6R2SWTAT" def fetch_alpha_vantage_data(api_key, symbol): try: url = f'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={symbol}&interval=5min&apikey={api_key}' response = requests.get(url) response.raise_for_status() # Raise an error for bad responses alpha_vantage_data = response.json() return alpha_vantage_data except requests.RequestException as e: st.error(f"Error fetching data: {e}") return None def main(): st.title("Stock Trend Predictor") # User input for stock symbol symbol = st.text_input("Enter Stock Symbol (e.g., IBM):") if not symbol: st.warning("Please enter a valid stock symbol.") st.stop() # Use the hard-coded API key api_key = API_KEY # Fetch Alpha Vantage data alpha_vantage_data = fetch_alpha_vantage_data(api_key, symbol) if alpha_vantage_data: # Extract relevant data from Alpha Vantage response alpha_vantage_time_series = alpha_vantage_data.get('Time Series (5min)', {}) df = pd.DataFrame(alpha_vantage_time_series).T df.index = pd.to_datetime(df.index) df = df.dropna(axis=0) # Display the raw data st.subheader("Raw Data:") st.write(df) if __name__ == "__main__": main()