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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import yfinance as yf
|
| 3 |
+
import streamlit.components.v1 as components
|
| 4 |
+
|
| 5 |
+
# Set the page layout
|
| 6 |
+
st.set_page_config(layout="wide")
|
| 7 |
+
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
import numpy as np
|
| 10 |
+
import base64
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import time
|
| 13 |
+
from keras.models import load_model
|
| 14 |
+
from sklearn.preprocessing import MinMaxScaler
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
if "framework" not in st.session_state:
|
| 18 |
+
st.session_state.framework = "gen"
|
| 19 |
+
# Initialize state
|
| 20 |
+
if "show_modal" not in st.session_state:
|
| 21 |
+
st.session_state.show_modal = False
|
| 22 |
+
if "show_overlay" not in st.session_state:
|
| 23 |
+
st.session_state.show_overlay = False
|
| 24 |
+
if "model" not in st.session_state:
|
| 25 |
+
st.session_state.model = "best_bilstm_model.h5"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Loading model
|
| 29 |
+
@st.cache_resource
|
| 30 |
+
def load_lstm_model(path):
|
| 31 |
+
return load_model(path)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@st.cache_resource
|
| 35 |
+
def load_data():
|
| 36 |
+
data = yf.download("AMZN", period="4y", multi_level_index=False)
|
| 37 |
+
data.reset_index(inplace=True)
|
| 38 |
+
return data
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
#################################################################################################
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def predict_future_prices(
|
| 45 |
+
df: pd.DataFrame, n_future_days: int, model_path: str = st.session_state.model
|
| 46 |
+
) -> tuple[plt.Figure, pd.DataFrame]:
|
| 47 |
+
# Ensure DataFrame is sorted and clean
|
| 48 |
+
df = df.sort_values("Date").dropna(subset=["Close"])
|
| 49 |
+
df = df.reset_index(drop=True)
|
| 50 |
+
|
| 51 |
+
# Scale data
|
| 52 |
+
scaler = MinMaxScaler()
|
| 53 |
+
prices = df["Close"].values.reshape(-1, 1)
|
| 54 |
+
scaled_prices = scaler.fit_transform(prices)
|
| 55 |
+
|
| 56 |
+
# Load model and get timesteps
|
| 57 |
+
model = load_lstm_model(model_path)
|
| 58 |
+
n_steps = model.input_shape[1]
|
| 59 |
+
|
| 60 |
+
# --- Calculate validation error (historical residuals) ---
|
| 61 |
+
X_hist, y_hist = [], []
|
| 62 |
+
for i in range(n_steps, len(scaled_prices)):
|
| 63 |
+
X_hist.append(scaled_prices[i - n_steps : i])
|
| 64 |
+
y_hist.append(scaled_prices[i])
|
| 65 |
+
X_hist = np.array(X_hist)
|
| 66 |
+
y_hist = np.array(y_hist)
|
| 67 |
+
|
| 68 |
+
# Predict historical values
|
| 69 |
+
hist_predictions = model.predict(X_hist, verbose=0)
|
| 70 |
+
|
| 71 |
+
# Calculate residuals (error)
|
| 72 |
+
hist_prices_rescaled = scaler.inverse_transform(y_hist.reshape(-1, 1)).flatten()
|
| 73 |
+
hist_preds_rescaled = scaler.inverse_transform(
|
| 74 |
+
hist_predictions.reshape(-1, 1)
|
| 75 |
+
).flatten()
|
| 76 |
+
residuals = hist_prices_rescaled - hist_preds_rescaled
|
| 77 |
+
error_std = np.std(residuals) # Key metric for confidence interval
|
| 78 |
+
|
| 79 |
+
# --- Predict future values ---
|
| 80 |
+
last_sequence = scaled_prices[-n_steps:]
|
| 81 |
+
predicted = []
|
| 82 |
+
current_sequence = last_sequence.copy()
|
| 83 |
+
|
| 84 |
+
for _ in range(n_future_days):
|
| 85 |
+
pred = model.predict(current_sequence.reshape(1, n_steps, 1), verbose=0)
|
| 86 |
+
predicted.append(pred[0, 0])
|
| 87 |
+
current_sequence = np.append(current_sequence[1:], [[pred[0, 0]]], axis=0)
|
| 88 |
+
|
| 89 |
+
# Rescale predictions
|
| 90 |
+
predicted_prices = scaler.inverse_transform(
|
| 91 |
+
np.array(predicted).reshape(-1, 1)
|
| 92 |
+
).flatten()
|
| 93 |
+
future_dates = pd.date_range(
|
| 94 |
+
df["Date"].iloc[-1] + pd.Timedelta(days=1), periods=n_future_days
|
| 95 |
+
)
|
| 96 |
+
prediction_df = pd.DataFrame(
|
| 97 |
+
{"Date": future_dates, "Predicted Price": predicted_prices}
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# --- Plotting with confidence interval ---
|
| 101 |
+
plt.rcParams["font.family"] = "Times New Roman "
|
| 102 |
+
|
| 103 |
+
fig, ax = plt.subplots(figsize=(10, 6), facecolor="none")
|
| 104 |
+
ax.patch.set_alpha(0)
|
| 105 |
+
fig.patch.set_alpha(0)
|
| 106 |
+
|
| 107 |
+
# Historical data
|
| 108 |
+
ax.plot(df["Date"], df["Close"], label="Historical", color="cyan", linewidth=2)
|
| 109 |
+
|
| 110 |
+
# Confidence interval (expanding uncertainty)
|
| 111 |
+
days = np.arange(1, n_future_days + 1)
|
| 112 |
+
expanding_std = error_std * np.sqrt(days)
|
| 113 |
+
upper = predicted_prices + 1.96 * expanding_std # 95% CI
|
| 114 |
+
lower = predicted_prices - 1.96 * expanding_std
|
| 115 |
+
|
| 116 |
+
ax.fill_between(
|
| 117 |
+
prediction_df["Date"],
|
| 118 |
+
lower,
|
| 119 |
+
upper,
|
| 120 |
+
color="lightblue",
|
| 121 |
+
alpha=0.3,
|
| 122 |
+
label="95% Confidence Interval",
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# Predicted points (magenta dots)
|
| 126 |
+
ax.plot(
|
| 127 |
+
prediction_df["Date"],
|
| 128 |
+
prediction_df["Predicted Price"],
|
| 129 |
+
label=f"Next {n_future_days} Days Forecast",
|
| 130 |
+
color="magenta",
|
| 131 |
+
linestyle="None",
|
| 132 |
+
marker=".",
|
| 133 |
+
markersize=5,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
# ---- NEW: Trend line spanning historical + forecasted data ----
|
| 137 |
+
# Combine historical and predicted dates/prices
|
| 138 |
+
all_dates = np.concatenate([df["Date"].values, prediction_df["Date"].values])
|
| 139 |
+
all_prices = np.concatenate(
|
| 140 |
+
[df["Close"].values, prediction_df["Predicted Price"].values]
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
window_size = 30
|
| 144 |
+
trend_line = pd.Series(all_prices).rolling(window=window_size, min_periods=1).mean()
|
| 145 |
+
|
| 146 |
+
# Plotting the trend line (blue dashed)
|
| 147 |
+
ax.plot(
|
| 148 |
+
all_dates,
|
| 149 |
+
trend_line,
|
| 150 |
+
color="blue",
|
| 151 |
+
linestyle="--",
|
| 152 |
+
linewidth=1.5,
|
| 153 |
+
label="Long-Term Trend",
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
# Style
|
| 157 |
+
ax.set_title(
|
| 158 |
+
f"📈 Stock Price Forecast ({st.session_state.model})",
|
| 159 |
+
fontsize=14,
|
| 160 |
+
fontweight="bold",
|
| 161 |
+
)
|
| 162 |
+
ax.set_xlabel("Date", fontsize=12)
|
| 163 |
+
ax.set_ylabel("Price", fontsize=12)
|
| 164 |
+
ax.legend(loc="upper left")
|
| 165 |
+
ax.grid(True, linestyle="--", alpha=0.6)
|
| 166 |
+
|
| 167 |
+
return fig, prediction_df
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
#####################################################################################################
|
| 171 |
+
|
| 172 |
+
# Function to load data
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
# Load the data
|
| 176 |
+
# data = load_data()
|
| 177 |
+
# import matplotlib.pyplot as plt
|
| 178 |
+
# Path to your logo image
|
| 179 |
+
encoded_logo = "tensorflow.png"
|
| 180 |
+
main_bg_ext = "png"
|
| 181 |
+
main_bg = "Picture3.png "
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
if st.session_state.framework == "lstm":
|
| 185 |
+
bg_color = "#FF5733" # For example, a warm red/orange
|
| 186 |
+
bg_color_iv = "orange" # For example, a warm red/orange
|
| 187 |
+
text_h1 = "BI-DIRECTIONAL"
|
| 188 |
+
text_i = "Long short term memory"
|
| 189 |
+
model = "TENSORFLOW"
|
| 190 |
+
st.session_state.model = "best_bilstm_model.h5"
|
| 191 |
+
if st.session_state.framework == "gru":
|
| 192 |
+
bg_color = "#FF5733" # For example, a warm red/orange
|
| 193 |
+
bg_color_iv = "orange" # For example, a warm red/orange
|
| 194 |
+
text_h1 = "GATED RECURRENT UNIT"
|
| 195 |
+
text_i = "Recurrent Neural Network"
|
| 196 |
+
model = "TENSORFLOW"
|
| 197 |
+
st.session_state.model = "best_gru_model.h5"
|
| 198 |
+
if st.session_state.framework == "gen":
|
| 199 |
+
bg_color = "#FF5733" # For example, a warm red/orange
|
| 200 |
+
bg_color_iv = "orange" # For example, a warm red/orange
|
| 201 |
+
text_h1 = "Amazon Stock Predictor"
|
| 202 |
+
text_i = "21 Days Ahead of the Market"
|
| 203 |
+
model = "TENSORFLOW"
|
| 204 |
+
st.markdown(
|
| 205 |
+
f"""
|
| 206 |
+
<style>
|
| 207 |
+
/* Container for logo and text */
|
| 208 |
+
/* Container for logo and text */
|
| 209 |
+
.logo-text-container {{
|
| 210 |
+
position: fixed;
|
| 211 |
+
top: 20px; /* Adjust vertical position */
|
| 212 |
+
left: 30px; /* Align with sidebar */
|
| 213 |
+
display: flex;
|
| 214 |
+
align-items: center;
|
| 215 |
+
gap: 25px;
|
| 216 |
+
width: 70%;
|
| 217 |
+
z-index:1000;
|
| 218 |
+
}}
|
| 219 |
+
|
| 220 |
+
/* Logo styling */
|
| 221 |
+
.logo-text-container img {{
|
| 222 |
+
width: 50px; /* Adjust logo size */
|
| 223 |
+
border-radius: 10px; /* Optional: round edges */
|
| 224 |
+
margin-left:-5px;
|
| 225 |
+
margin-top: -15px;
|
| 226 |
+
|
| 227 |
+
}}
|
| 228 |
+
|
| 229 |
+
/* Bold text styling */
|
| 230 |
+
.logo-text-container h1 {{
|
| 231 |
+
font-family: Nunito;
|
| 232 |
+
color: #0175C2;
|
| 233 |
+
font-size: 25px;
|
| 234 |
+
font-weight: bold;
|
| 235 |
+
margin-right :100px;
|
| 236 |
+
padding:0px;
|
| 237 |
+
top:0;
|
| 238 |
+
margin-top: -12px;
|
| 239 |
+
}}
|
| 240 |
+
.logo-text-container i{{
|
| 241 |
+
font-family: Nunito;
|
| 242 |
+
color: orange;
|
| 243 |
+
font-size: 15px;
|
| 244 |
+
margin-right :10px;
|
| 245 |
+
padding:0px;
|
| 246 |
+
margin-left:-18.5%;
|
| 247 |
+
margin-top:1%;
|
| 248 |
+
}}
|
| 249 |
+
|
| 250 |
+
/* Sidebar styling */
|
| 251 |
+
section[data-testid="stSidebar"][aria-expanded="true"] {{
|
| 252 |
+
margin-top: 100px !important; /* Space for the logo */
|
| 253 |
+
border-radius: 0 60px 0px 60px !important; /* Top-left and bottom-right corners */
|
| 254 |
+
width: 200px !important; /* Sidebar width */
|
| 255 |
+
background: none; /* No background */
|
| 256 |
+
color: white !important;
|
| 257 |
+
}}
|
| 258 |
+
|
| 259 |
+
header[data-testid="stHeader"] {{
|
| 260 |
+
background: transparent !important;
|
| 261 |
+
margin-right: 100px !important;
|
| 262 |
+
margin-top: 1px !important;
|
| 263 |
+
z-index: 1 !important;
|
| 264 |
+
|
| 265 |
+
color: blue; /* White text */
|
| 266 |
+
font-family: "Times New Roman " !important; /* Font */
|
| 267 |
+
font-size: 18px !important; /* Font size */
|
| 268 |
+
font-weight: bold !important; /* Bold text */
|
| 269 |
+
padding: 10px 20px; /* Padding for buttons */
|
| 270 |
+
border: none; /* Remove border */
|
| 271 |
+
border-radius: 35px; /* Rounded corners */
|
| 272 |
+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2); /* Shadow effect */
|
| 273 |
+
transition: all 0.3s ease-in-out; /* Smooth transition */
|
| 274 |
+
display: flex;
|
| 275 |
+
align-items: center;
|
| 276 |
+
justify-content: center;
|
| 277 |
+
margin: 10px 0;
|
| 278 |
+
width:90%;
|
| 279 |
+
left:5.5%;
|
| 280 |
+
height:60px;
|
| 281 |
+
margin-top:70px;
|
| 282 |
+
backdrop-filter: blur(10px);
|
| 283 |
+
border: 2px solid rgba(255, 255, 255, 0.4); /* Light border */
|
| 284 |
+
|
| 285 |
+
}}
|
| 286 |
+
|
| 287 |
+
div[data-testid="stDecoration"] {{
|
| 288 |
+
background-image: none;
|
| 289 |
+
}}
|
| 290 |
+
|
| 291 |
+
div[data-testid="stApp"] {{
|
| 292 |
+
background: url(data:image/{main_bg_ext};base64,{base64.b64encode(open(main_bg, "rb").read()).decode()});
|
| 293 |
+
background-size: cover; /* Ensure the image covers the full page */
|
| 294 |
+
background-position: center;
|
| 295 |
+
background-repeat:no-repeat;
|
| 296 |
+
height: 98vh;
|
| 297 |
+
width: 99.3%;
|
| 298 |
+
border-radius: 20px !important;
|
| 299 |
+
margin-left: 5px;
|
| 300 |
+
margin-right: 20px;
|
| 301 |
+
margin-top: 10px;
|
| 302 |
+
overflow: hidden;
|
| 303 |
+
backdrop-filter: blur(10px); /* Glass effect */
|
| 304 |
+
-webkit-backdrop-filter: blur(10px);
|
| 305 |
+
border: 1px solid rgba(255, 255, 255, 0.2); /* Light border */
|
| 306 |
+
|
| 307 |
+
}}
|
| 308 |
+
|
| 309 |
+
div[data-testid="stSidebarNav"] {{
|
| 310 |
+
display: none;
|
| 311 |
+
}}
|
| 312 |
+
|
| 313 |
+
div[data-testid="stSlider"] {{
|
| 314 |
+
margin-top:45px;
|
| 315 |
+
}}
|
| 316 |
+
label[data-testid="stWidgetLabel"]{{
|
| 317 |
+
margin-left:20px !important;
|
| 318 |
+
}}
|
| 319 |
+
|
| 320 |
+
div[data-baseweb="slider"] {{
|
| 321 |
+
border-radius: 30px;
|
| 322 |
+
padding-right:40px;
|
| 323 |
+
z-index: 1;
|
| 324 |
+
/* Glass effect background */
|
| 325 |
+
backdrop-filter: blur(2px);
|
| 326 |
+
-webkit-backdrop-filter: blur(12px);
|
| 327 |
+
/* Shiny blue borders (left & right) */
|
| 328 |
+
border-top: 2px solid rgba(255, 255, 155, 0.4); /* Light border */
|
| 329 |
+
margin-left:13px;
|
| 330 |
+
border-bottom: 2px solid rgba(255, 255, 155, 0.4); /* Light border */
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
}}
|
| 334 |
+
div[data-baseweb="slider"] > :nth-child(1)> div {{
|
| 335 |
+
margin-left:20px !important;
|
| 336 |
+
margin-top:10px;
|
| 337 |
+
}}
|
| 338 |
+
div[data-testid="stSliderTickBarMin"]{{
|
| 339 |
+
background:none !important;
|
| 340 |
+
margin-left:20px !important;
|
| 341 |
+
font-size:12px;
|
| 342 |
+
margin-bottom:5px;
|
| 343 |
+
font-family: "Times New Roman " !important; /* Font */
|
| 344 |
+
}}
|
| 345 |
+
div[data-testid="stSliderTickBarMax"]{{
|
| 346 |
+
background:none !important;
|
| 347 |
+
font-size:12px;
|
| 348 |
+
margin-bottom:5px;
|
| 349 |
+
|
| 350 |
+
font-family: "Times New Roman " !important; /* Font */
|
| 351 |
+
}}
|
| 352 |
+
div[data-testid="stSliderThumbValue"]{{
|
| 353 |
+
font-size:12px;
|
| 354 |
+
font-family: "Times New Roman " !important; /* Font */
|
| 355 |
+
|
| 356 |
+
}}
|
| 357 |
+
div[data-testid="stProgress"]{{
|
| 358 |
+
margin-right:25px;
|
| 359 |
+
margin-top:-70px;
|
| 360 |
+
height:10px !important;
|
| 361 |
+
|
| 362 |
+
}}
|
| 363 |
+
[class*="st-key-content-container-3"] {{
|
| 364 |
+
margin-top: 80px; /* Adjust top margin */
|
| 365 |
+
marging-left:50px !important;
|
| 366 |
+
color:orange;
|
| 367 |
+
|
| 368 |
+
}}
|
| 369 |
+
|
| 370 |
+
/* Button row styling */
|
| 371 |
+
.button-row {{
|
| 372 |
+
display: flex;
|
| 373 |
+
justify-content: flex-start;
|
| 374 |
+
gap: 20px;
|
| 375 |
+
margin-bottom: 20px;
|
| 376 |
+
}}
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
.custom-button:hover {{
|
| 381 |
+
background-color: #0056b3;
|
| 382 |
+
}}
|
| 383 |
+
div.stButton > button p{{
|
| 384 |
+
color: orange !important;
|
| 385 |
+
font-weight:bold;
|
| 386 |
+
}}
|
| 387 |
+
div.stButton > button {{
|
| 388 |
+
background: rgba(255, 255, 255, 0.2);
|
| 389 |
+
color: orange !important; /* White text */
|
| 390 |
+
font-family: "Times New Roman " !important; /* Font */
|
| 391 |
+
font-size: 18px !important; /* Font size */
|
| 392 |
+
font-weight: bold !important; /* Bold text */
|
| 393 |
+
padding: 10px 20px; /* Padding for buttons */
|
| 394 |
+
border: none; /* Remove border */
|
| 395 |
+
border-radius: 35px; /* Rounded corners */
|
| 396 |
+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2); /* Shadow effect */
|
| 397 |
+
transition: all 0.3s ease-in-out; /* Smooth transition */
|
| 398 |
+
display: flex;
|
| 399 |
+
align-items: center;
|
| 400 |
+
justify-content: center;
|
| 401 |
+
margin: 10px 0;
|
| 402 |
+
width:160px;
|
| 403 |
+
height:50px;
|
| 404 |
+
margin-top:5px;
|
| 405 |
+
|
| 406 |
+
}}
|
| 407 |
+
|
| 408 |
+
/* Hover effect */
|
| 409 |
+
div.stButton > button:hover {{
|
| 410 |
+
background: rgba(255, 255, 255, 0.2);
|
| 411 |
+
box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.4); /* Enhanced shadow on hover */
|
| 412 |
+
transform: scale(1.05); /* Slightly enlarge button */
|
| 413 |
+
transform: scale(1.1); /* Slight zoom on hover */
|
| 414 |
+
box-shadow: 0px 4px 12px rgba(255, 255, 255, 0.4); /* Glow effect */
|
| 415 |
+
}}
|
| 416 |
+
|
| 417 |
+
div[data-testid="stMarkdownContainer"] p {{
|
| 418 |
+
font-family: "Times New Roman" !important; /* Elegant font for title */
|
| 419 |
+
color:black !important;
|
| 420 |
+
|
| 421 |
+
}}
|
| 422 |
+
.titles{{
|
| 423 |
+
margin-top:-50px !important;
|
| 424 |
+
margin-left:-40px;
|
| 425 |
+
font-family: "Times New Roman" !important;
|
| 426 |
+
|
| 427 |
+
}}
|
| 428 |
+
.header {{
|
| 429 |
+
display: flex;
|
| 430 |
+
align-items: center;
|
| 431 |
+
gap: 20px; /* Optional: adds space between image and text */
|
| 432 |
+
}}
|
| 433 |
+
.header img {{
|
| 434 |
+
height: 120px; /* Adjust as needed */
|
| 435 |
+
margin-top:-15px;
|
| 436 |
+
}}
|
| 437 |
+
/* Title styling */
|
| 438 |
+
.header h1{{
|
| 439 |
+
font-family: "Times New Roman" !important; /* Elegant font for title
|
| 440 |
+
font-size: 2.7rem;
|
| 441 |
+
font-weight: bold;
|
| 442 |
+
margin-left: 5px;
|
| 443 |
+
/* margin-top:-50px;*/
|
| 444 |
+
margin-bottom:30px;
|
| 445 |
+
padding: 0;
|
| 446 |
+
color: black; /* Neutral color for text */
|
| 447 |
+
}}
|
| 448 |
+
.titles .content{{
|
| 449 |
+
font-family: "Times New Roman" !important; /* Elegant font for title */
|
| 450 |
+
font-size: 1.2rem;
|
| 451 |
+
margin-left: 150px;
|
| 452 |
+
margin-bottom:1px;
|
| 453 |
+
padding: 0;
|
| 454 |
+
color:black; /* Neutral color for text */
|
| 455 |
+
}}
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
</style>
|
| 461 |
+
|
| 462 |
+
""",
|
| 463 |
+
unsafe_allow_html=True,
|
| 464 |
+
)
|
| 465 |
+
# Overlay container
|
| 466 |
+
st.markdown(
|
| 467 |
+
f"""
|
| 468 |
+
<style>
|
| 469 |
+
.logo-text-containers {{
|
| 470 |
+
position: absolute;
|
| 471 |
+
top: -60px;
|
| 472 |
+
right: 40px;
|
| 473 |
+
background-color: rgba(255, 255, 255, 0.9);
|
| 474 |
+
padding: 15px;
|
| 475 |
+
border-radius: 12px;
|
| 476 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
| 477 |
+
z-index: 10;
|
| 478 |
+
width:80vw;
|
| 479 |
+
height:620px;
|
| 480 |
+
}}
|
| 481 |
+
.logo-text-containers img {{
|
| 482 |
+
height: 40px;
|
| 483 |
+
right:0;
|
| 484 |
+
}}
|
| 485 |
+
.logo-text-containers h1 {{
|
| 486 |
+
display: inline;
|
| 487 |
+
font-size: 20px;
|
| 488 |
+
vertical-align: middle;
|
| 489 |
+
}}
|
| 490 |
+
.logo-text-containers i {{
|
| 491 |
+
display: block;
|
| 492 |
+
margin-top: 5px;
|
| 493 |
+
font-size: 14px;
|
| 494 |
+
color: #333;
|
| 495 |
+
}}
|
| 496 |
+
|
| 497 |
+
[class*="st-key-close-btn"] {{
|
| 498 |
+
top: 5px;
|
| 499 |
+
font-size: 20px;
|
| 500 |
+
font-weight: bold !important;
|
| 501 |
+
cursor: pointer;
|
| 502 |
+
position:absolute;
|
| 503 |
+
margin-left:1150px;
|
| 504 |
+
color:red !important;
|
| 505 |
+
z-index:1000;
|
| 506 |
+
}}
|
| 507 |
+
[class*="st-key-close-btn"]:hover {{
|
| 508 |
+
color: #f00;
|
| 509 |
+
}}
|
| 510 |
+
[class*="st-key-divider-col"] {{
|
| 511 |
+
border-left: 3px solid rgba(255, 255, 155, 0.5); /* Light border */
|
| 512 |
+
border-radius: 35px; /* Rounded corners */
|
| 513 |
+
margin-top:-15px;
|
| 514 |
+
margin-left:3px;
|
| 515 |
+
|
| 516 |
+
}}
|
| 517 |
+
[class*="st-key-col1"] {{
|
| 518 |
+
border-right: 3px solid rgba(255, 255, 155, 0.5); /* Light border */
|
| 519 |
+
border-radius: 35px; /* Rounded corners */
|
| 520 |
+
margin-left:20px;
|
| 521 |
+
margin-top:-15px;
|
| 522 |
+
|
| 523 |
+
}}
|
| 524 |
+
|
| 525 |
+
[class*="st-key-logo-text-containers"] {{
|
| 526 |
+
margin: 10px; /* Set a margin inside the container */
|
| 527 |
+
max-width: 100%;
|
| 528 |
+
overflow: hidden;
|
| 529 |
+
|
| 530 |
+
position: absolute;
|
| 531 |
+
top:-43px;
|
| 532 |
+
left:10px;
|
| 533 |
+
overflow: hidden;
|
| 534 |
+
background-color: tansparent;
|
| 535 |
+
padding: 15px;
|
| 536 |
+
border-radius: 30px;
|
| 537 |
+
padding-right:40px;
|
| 538 |
+
z-index: 1;
|
| 539 |
+
width:88vw;
|
| 540 |
+
height:660px;
|
| 541 |
+
/* Glass effect background */
|
| 542 |
+
background: rgba(255, 255, 255, 0.15);
|
| 543 |
+
backdrop-filter: blur(12px);
|
| 544 |
+
-webkit-backdrop-filter: blur(12px);
|
| 545 |
+
/* Shiny blue borders (left & right) */
|
| 546 |
+
border-left: 3px solid rgba(255, 255, 255, 0.9); /* Light border */
|
| 547 |
+
border-right: 3px solid rgba(255, 255, 255, 0.9); /* Light border */
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
}}
|
| 551 |
+
|
| 552 |
+
@media (max-width: 768px) {{
|
| 553 |
+
.logo-text-container h1 {{
|
| 554 |
+
font-size: 12px;
|
| 555 |
+
|
| 556 |
+
}}
|
| 557 |
+
.logo-text-container i {{
|
| 558 |
+
font-size: 10px;
|
| 559 |
+
ma
|
| 560 |
+
}}
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
.logo-text-container img {{
|
| 564 |
+
width: 30px; /* Adjust logo size */
|
| 565 |
+
border-radius: 10px; /* Optional: round edges */
|
| 566 |
+
margin-left:15px;
|
| 567 |
+
margin-top: -35px;
|
| 568 |
+
|
| 569 |
+
}}
|
| 570 |
+
|
| 571 |
+
}}
|
| 572 |
+
</style>
|
| 573 |
+
""",
|
| 574 |
+
unsafe_allow_html=True,
|
| 575 |
+
)
|
| 576 |
+
|
| 577 |
+
if st.session_state.show_overlay:
|
| 578 |
+
|
| 579 |
+
with st.container(key="logo-text-containers"):
|
| 580 |
+
if st.button("✕", key="close-btn"):
|
| 581 |
+
st.session_state.show_overlay = False
|
| 582 |
+
st.session_state.framework = "gen"
|
| 583 |
+
st.rerun()
|
| 584 |
+
with st.spinner("Downloading and processing the Data..."):
|
| 585 |
+
progress_bar = st.progress(0)
|
| 586 |
+
for i in range(1, 11):
|
| 587 |
+
time.sleep(0.6)
|
| 588 |
+
progress_bar.progress(i * 10)
|
| 589 |
+
with st.container(key="content"):
|
| 590 |
+
days = st.slider(
|
| 591 |
+
"Amazon Stock Insight: Predictive Analytics Over 21 Days",
|
| 592 |
+
1,
|
| 593 |
+
21,
|
| 594 |
+
7,
|
| 595 |
+
key="days_slider",
|
| 596 |
+
)
|
| 597 |
+
|
| 598 |
+
col1, col2 = st.columns([2.5, 3])
|
| 599 |
+
data = load_data()
|
| 600 |
+
if data is not None and not data.empty:
|
| 601 |
+
fig, future_data = predict_future_prices(
|
| 602 |
+
data, days+1, st.session_state.model
|
| 603 |
+
)
|
| 604 |
+
with col1:
|
| 605 |
+
with st.container(key="col1"):
|
| 606 |
+
future_data["Date"] = future_data["Date"].dt.strftime("%Y-%m-%d")
|
| 607 |
+
future_data = future_data[1:]
|
| 608 |
+
styled_html = (
|
| 609 |
+
future_data.style.set_table_attributes('class="glass-table"')
|
| 610 |
+
.set_table_styles(
|
| 611 |
+
[
|
| 612 |
+
{
|
| 613 |
+
"selector": "th",
|
| 614 |
+
"props": [
|
| 615 |
+
("padding", "12px"),
|
| 616 |
+
("color", "#000"),
|
| 617 |
+
(
|
| 618 |
+
"background-color",
|
| 619 |
+
"rgba(255, 255, 255, 0.15)",
|
| 620 |
+
),
|
| 621 |
+
],
|
| 622 |
+
},
|
| 623 |
+
{
|
| 624 |
+
"selector": "td",
|
| 625 |
+
"props": [
|
| 626 |
+
("padding", "10px"),
|
| 627 |
+
("color", "#000"),
|
| 628 |
+
("border-bottom", "1px solid rgba(0,0,0,0.1)"),
|
| 629 |
+
],
|
| 630 |
+
},
|
| 631 |
+
{
|
| 632 |
+
"selector": "table",
|
| 633 |
+
"props": [
|
| 634 |
+
("width", "100%"),
|
| 635 |
+
("border-collapse", "collapse"),
|
| 636 |
+
],
|
| 637 |
+
},
|
| 638 |
+
]
|
| 639 |
+
)
|
| 640 |
+
.to_html()
|
| 641 |
+
)
|
| 642 |
+
|
| 643 |
+
|
| 644 |
+
# Glassmorphism CSS + vertical scroll + black text
|
| 645 |
+
glass_css = """
|
| 646 |
+
<style>
|
| 647 |
+
/* Outer shell for glass effect & border radius */
|
| 648 |
+
.outer-glass-wrapper {
|
| 649 |
+
backdrop-filter: blur(10px);
|
| 650 |
+
-webkit-backdrop-filter: blur(10px);
|
| 651 |
+
background: rgba(255, 255, 255, 0.15);
|
| 652 |
+
border-radius: 20px;
|
| 653 |
+
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
|
| 654 |
+
max-height: 600px;
|
| 655 |
+
max-width: 800px;
|
| 656 |
+
overflow: hidden;
|
| 657 |
+
margin-right: 15px;
|
| 658 |
+
margin-left:3px;
|
| 659 |
+
font-family: "Times New Roman " !important; /* Font */
|
| 660 |
+
|
| 661 |
+
font-size: 14px;
|
| 662 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
| 663 |
+
margin-bottom:30px;
|
| 664 |
+
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
/* Inner scrolling container */
|
| 668 |
+
.glass-container {
|
| 669 |
+
max-height: 410px;
|
| 670 |
+
overflow-y: auto;
|
| 671 |
+
padding: 16px 24px 16px 16px; /* right padding gives room for scrollbar */
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
/* Scrollbar styles */
|
| 675 |
+
.glass-container::-webkit-scrollbar {
|
| 676 |
+
width: 4px;
|
| 677 |
+
}
|
| 678 |
+
.glass-container::-webkit-scrollbar-track {
|
| 679 |
+
background: transparent;
|
| 680 |
+
}
|
| 681 |
+
.glass-container::-webkit-scrollbar-thumb {
|
| 682 |
+
background-color: rgba(0, 0, 0, 0.3);
|
| 683 |
+
border-radius: 10px;
|
| 684 |
+
}
|
| 685 |
+
.glass-container {
|
| 686 |
+
scrollbar-width: thin;
|
| 687 |
+
scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
/* Table styling */
|
| 691 |
+
.glass-table {
|
| 692 |
+
width: 100%;
|
| 693 |
+
}
|
| 694 |
+
.glass-table th, .glass-table td {
|
| 695 |
+
text-align: left;
|
| 696 |
+
white-space: nowrap;
|
| 697 |
+
color: #000;
|
| 698 |
+
}
|
| 699 |
+
</style>
|
| 700 |
+
"""
|
| 701 |
+
|
| 702 |
+
st.markdown(glass_css, unsafe_allow_html=True)
|
| 703 |
+
st.markdown(
|
| 704 |
+
f""" <div class="outer-glass-wrapper">
|
| 705 |
+
<div class="glass-container">
|
| 706 |
+
{styled_html}</div> </div>
|
| 707 |
+
""",
|
| 708 |
+
unsafe_allow_html=True,
|
| 709 |
+
)
|
| 710 |
+
|
| 711 |
+
with col2:
|
| 712 |
+
with st.container(key="divider-col"):
|
| 713 |
+
st.pyplot(fig)
|
| 714 |
+
|
| 715 |
+
else:
|
| 716 |
+
st.error("No data loaded. Please check your internet connection.")
|
| 717 |
+
# Show overlay if triggered
|
| 718 |
+
st.markdown(
|
| 719 |
+
f""" <div class="logo-text-container">
|
| 720 |
+
<img src="data:image/png;base64,{base64.b64encode(open("tensorflow.png","rb").read()).decode()}" alt="Uploaded Image">
|
| 721 |
+
<h1>{text_h1}<br></h1>
|
| 722 |
+
<i>{ text_i}</i>
|
| 723 |
+
</div>
|
| 724 |
+
|
| 725 |
+
""",
|
| 726 |
+
unsafe_allow_html=True,
|
| 727 |
+
)
|
| 728 |
+
|
| 729 |
+
|
| 730 |
+
st.markdown(
|
| 731 |
+
f""" <div class="titles">
|
| 732 |
+
<div class = "header">
|
| 733 |
+
<img src="data:image/png;base64,{base64.b64encode(open("logo2.png","rb").read()).decode()}" alt="Uploaded Image">
|
| 734 |
+
<h1></br>ACTIONS </br> TREND ANALYTICS</h1>
|
| 735 |
+
</div>
|
| 736 |
+
<div class="content">
|
| 737 |
+
A deep learning-powered tool that analyzes Amazon's stock trends.<br>
|
| 738 |
+
the models(BI-Direcional Lstm and GRU) predicts future market<br> actions based on past trends,
|
| 739 |
+
providing a confidence score to <br> help users interpret the data more accurately and take timely actions.
|
| 740 |
+
</div>
|
| 741 |
+
</div>
|
| 742 |
+
""",
|
| 743 |
+
unsafe_allow_html=True,
|
| 744 |
+
)
|
| 745 |
+
|
| 746 |
+
|
| 747 |
+
with st.container(key="content-container-3"):
|
| 748 |
+
col1, col2 = st.columns([1.5, 10.5])
|
| 749 |
+
with col1:
|
| 750 |
+
if st.button(" BIDIR-LSTM"):
|
| 751 |
+
st.session_state.framework = "lstm"
|
| 752 |
+
st.session_state.show_overlay = True
|
| 753 |
+
st.rerun()
|
| 754 |
+
with col2:
|
| 755 |
+
if st.button("GRU"):
|
| 756 |
+
st.session_state.framework = "gru"
|
| 757 |
+
st.session_state.show_overlay = True
|
| 758 |
+
st.rerun()
|