File size: 1,344 Bytes
bbe0030
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
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)