Spaces:
Build error
Build error
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import joblib | |
| import tensorflow as tf | |
| import matplotlib.pyplot as plt | |
| # Load trained model and scaler | |
| model = tf.keras.models.load_model("stock_model.h5") | |
| scaler = joblib.load("scaler.pkl") | |
| # Function to predict stock price | |
| def predict_stock_price(data): | |
| data = scaler.transform(data.reshape(-1, 1)) | |
| data = np.array([data]) | |
| predicted_price = model.predict(data) | |
| return scaler.inverse_transform(predicted_price)[0][0] | |
| # Streamlit UI | |
| st.title("๐ Stock Market Prediction App") | |
| uploaded_file = st.file_uploader("Upload Stock Data (CSV)", type="csv") | |
| if uploaded_file is not None: | |
| df = pd.read_csv(uploaded_file, parse_dates=["Date"], index_col="Date") | |
| st.write("Uploaded Data Preview:", df.tail()) | |
| if st.button("Predict Next Closing Price"): | |
| last_data = df["Close"].values[-50:] # Use last 50 days for prediction | |
| predicted_price = predict_stock_price(last_data) | |
| st.success(f"Predicted Closing Price: ${predicted_price:.2f}") | |
| # Plot stock price trend | |
| fig, ax = plt.subplots() | |
| ax.plot(df.index, df["Close"], label="Actual Price") | |
| ax.axhline(y=predicted_price, color="r", linestyle="--", label="Predicted Price") | |
| ax.legend() | |
| st.pyplot(fig) | |