Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import tensorflow as tf | |
| import joblib | |
| from PIL import Image | |
| from tensorflow.keras.models import load_model | |
| st.set_page_config(page_title="Nifty50 Predictor", layout="centered") | |
| st.title("๐ PricePulse") | |
| st.subheader("A Nifty50 Price Predictor", divider='grey') | |
| image = Image.open('nifty50stock.jpg') | |
| st.image(image) | |
| # Load model and scaler | |
| def load_artifacts(): | |
| model = load_model("final_nifty50_lstm.keras") | |
| scaler = joblib.load("scaler.pkl") | |
| return model, scaler | |
| model, scaler = load_artifacts() | |
| st.markdown("Enter the **last 3 closing prices** of NIFTY50 to predict the next price.") | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| price1 = st.number_input("Previous Day 3's Closing Price", value=22000.0, format="%.2f") | |
| with col2: | |
| price2 = st.number_input("Previous Day 2's Closing Price", value=22100.0, format="%.2f") | |
| with col3: | |
| price3 = st.number_input("Previous Day 1's Closing Price", value=22200.0, format="%.2f") | |
| last3 = np.array([price1, price2, price3]).reshape(-1, 1) | |
| last3_scaled = scaler.transform(last3).reshape(1, 3, 1) | |
| # Predict next step | |
| if st.button("๐ฎ Predict Next Day Price"): | |
| next_scaled = model.predict(last3_scaled, verbose=0)[0][0] | |
| next_price = scaler.inverse_transform([[next_scaled]])[0][0] | |
| st.success(f"Predicted Next Closing Price: โน{next_price:.2f}") | |
| # Predict next 10 steps recursively | |
| if st.button("๐ Predict Next 10 Days"): | |
| seq = last3_scaled.copy() | |
| predictions = [] | |
| for _ in range(10): | |
| pred = model.predict(seq, verbose=0)[0][0] | |
| predictions.append(pred) | |
| seq = np.append(seq[:, 1:, :], [[[pred]]], axis=1) | |
| inv_preds = scaler.inverse_transform(np.array(predictions).reshape(-1, 1)).flatten() | |
| st.subheader("Next 10 Predicted Prices") | |
| st.table({"Day": [f"Day {i+1}" for i in range(10)], "Predicted Price (โน)": inv_preds}) | |
| st.caption("Made with โค๏ธ by Sourish") | |