Spaces:
Build error
Build error
| import pandas as pd | |
| import numpy as np | |
| import requests | |
| from sklearn.preprocessing import MinMaxScaler | |
| from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer | |
| import joblib | |
| from tensorflow.keras.models import load_model | |
| import os | |
| # Load model and scaler | |
| model = load_model("model.h5") | |
| scaler = joblib.load("scaler.pkl") if os.path.exists("scaler.pkl") else MinMaxScaler() | |
| analyzer = SentimentIntensityAnalyzer() | |
| # Fetch PSX data | |
| def get_psx_data(symbol="HBL"): | |
| dates = pd.date_range(end=pd.Timestamp.today(), periods=200) | |
| prices = np.linspace(100, 150, 200) + np.random.normal(0, 2, 200) | |
| df = pd.DataFrame({"Close": prices}, index=dates) | |
| return df | |
| # Sentiment analysis | |
| def get_sentiment(stock="HBL"): | |
| return np.random.uniform(-0.05, 0.05) | |
| # Predict next price | |
| def predict_next(df): | |
| data = scaler.fit_transform(df[["Close"]]) | |
| last60 = data[-60:].reshape(1, 60, 1) | |
| pred = model.predict(last60, verbose=0)[0][0] | |
| pred_real = scaler.inverse_transform([[pred]])[0][0] | |
| return pred_real | |