ritampatra commited on
Commit
bbe0030
·
verified ·
1 Parent(s): e675624

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +38 -0
  2. requirements.txt +8 -0
  3. scaler.pkl +3 -0
  4. stock_model.h5 +3 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import joblib
5
+ import tensorflow as tf
6
+ import matplotlib.pyplot as plt
7
+
8
+ # Load trained model and scaler
9
+ model = tf.keras.models.load_model("stock_model.h5")
10
+ scaler = joblib.load("scaler.pkl")
11
+
12
+ # Function to predict stock price
13
+ def predict_stock_price(data):
14
+ data = scaler.transform(data.reshape(-1, 1))
15
+ data = np.array([data])
16
+ predicted_price = model.predict(data)
17
+ return scaler.inverse_transform(predicted_price)[0][0]
18
+
19
+ # Streamlit UI
20
+ st.title("📈 Stock Market Prediction App")
21
+
22
+ uploaded_file = st.file_uploader("Upload Stock Data (CSV)", type="csv")
23
+
24
+ if uploaded_file is not None:
25
+ df = pd.read_csv(uploaded_file, parse_dates=["Date"], index_col="Date")
26
+ st.write("Uploaded Data Preview:", df.tail())
27
+
28
+ if st.button("Predict Next Closing Price"):
29
+ last_data = df["Close"].values[-50:] # Use last 50 days for prediction
30
+ predicted_price = predict_stock_price(last_data)
31
+ st.success(f"Predicted Closing Price: ${predicted_price:.2f}")
32
+
33
+ # Plot stock price trend
34
+ fig, ax = plt.subplots()
35
+ ax.plot(df.index, df["Close"], label="Actual Price")
36
+ ax.axhline(y=predicted_price, color="r", linestyle="--", label="Predicted Price")
37
+ ax.legend()
38
+ st.pyplot(fig)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ numpy
4
+ pandas
5
+ scikit-learn
6
+ matplotlib
7
+ seaborn
8
+ joblib
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2114c9c38dde724e6bdefbb4c05279fb67e1204c49c2b14ee3178872c067558
3
+ size 1023
stock_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21c9e70b75654343b0349d410f03030bcbe4b8b5a6ac8e957aeb1b0c5bb5c349
3
+ size 433576