Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,19 @@ import os
|
|
11 |
|
12 |
# --- Page Configuration ---
|
13 |
st.set_page_config(layout="wide")
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# --- Custom CSS ---
|
16 |
st.markdown("""
|
17 |
<style>
|
@@ -73,7 +85,8 @@ st.markdown("""
|
|
73 |
section[data-testid="stSidebar"] {
|
74 |
backdrop-filter: blur(10px);
|
75 |
background: rgba(255, 255, 255, 0.15);
|
76 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.
|
|
|
77 |
|
78 |
[data-testid="stSidebar"] h2 {
|
79 |
color: #FFFFFF; /* White headers in the sidebar */
|
@@ -153,6 +166,8 @@ def get_stock_data(ticker):
|
|
153 |
start_date = end_date - timedelta(days=4 * 365)
|
154 |
print(f"Fetching data for ticker: {ticker} from {start_date.date()} to {end_date.date()}")
|
155 |
data = yf.download(ticker, period="4y", multi_level_index=False)
|
|
|
|
|
156 |
if data.empty:
|
157 |
print(f"No data found for ticker: {ticker}")
|
158 |
return None
|
@@ -204,23 +219,12 @@ def predict_with_model(data: pd.DataFrame, n_days: int, model_path: str, model_t
|
|
204 |
return prediction_df
|
205 |
|
206 |
|
207 |
-
# --- Streamlit Session State Initialization ---
|
208 |
-
if 'run_button_clicked' not in st.session_state:
|
209 |
-
st.session_state.run_button_clicked = False
|
210 |
-
if 'loading' not in st.session_state:
|
211 |
-
st.session_state.loading = False
|
212 |
-
if 'data' not in st.session_state:
|
213 |
-
st.session_state.data = None
|
214 |
-
if 'predictions' not in st.session_state:
|
215 |
-
st.session_state.predictions = None
|
216 |
-
if 'error' not in st.session_state:
|
217 |
-
st.session_state.error = None
|
218 |
|
219 |
# --- Streamlit Sidebar Controls ---
|
220 |
with st.sidebar:
|
221 |
st.image("logo2.png", use_container_width=True)
|
222 |
st.markdown("Dashboard Controls")
|
223 |
-
ticker = st.text_input("Stock Ticker", st.session_state.get('last_ticker', "AMZN"),disabled=True).upper()
|
224 |
model_type = st.selectbox(
|
225 |
"Prediction Model",
|
226 |
("Bi-Directional LSTM", "Gated Recurrent Unit (GRU)"),
|
@@ -259,6 +263,7 @@ if st.session_state.run_button_clicked:
|
|
259 |
else:
|
260 |
st.session_state.data = get_stock_data(ticker)
|
261 |
|
|
|
262 |
if st.session_state.data is None:
|
263 |
st.session_state.error = f"Could not fetch data for ticker '{ticker}'. It may be an invalid symbol or network issue."
|
264 |
else:
|
|
|
11 |
|
12 |
# --- Page Configuration ---
|
13 |
st.set_page_config(layout="wide")
|
14 |
+
# --- Streamlit Session State Initialization ---
|
15 |
+
if 'run_button_clicked' not in st.session_state:
|
16 |
+
st.session_state.run_button_clicked = False
|
17 |
+
if 'loading' not in st.session_state:
|
18 |
+
st.session_state.loading = False
|
19 |
+
if 'data' not in st.session_state:
|
20 |
+
st.session_state.data = None
|
21 |
+
if 'predictions' not in st.session_state:
|
22 |
+
st.session_state.predictions = None
|
23 |
+
if 'error' not in st.session_state:
|
24 |
+
st.session_state.error = None
|
25 |
+
if 'last_ticker' not in st.session_state:
|
26 |
+
st.session_state['last_ticker'] = 'AMZN'
|
27 |
# --- Custom CSS ---
|
28 |
st.markdown("""
|
29 |
<style>
|
|
|
85 |
section[data-testid="stSidebar"] {
|
86 |
backdrop-filter: blur(10px);
|
87 |
background: rgba(255, 255, 255, 0.15);
|
88 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.01);
|
89 |
+
height:100px;
|
90 |
|
91 |
[data-testid="stSidebar"] h2 {
|
92 |
color: #FFFFFF; /* White headers in the sidebar */
|
|
|
166 |
start_date = end_date - timedelta(days=4 * 365)
|
167 |
print(f"Fetching data for ticker: {ticker} from {start_date.date()} to {end_date.date()}")
|
168 |
data = yf.download(ticker, period="4y", multi_level_index=False)
|
169 |
+
data.to_csv("AMZN_data.csv")
|
170 |
+
|
171 |
if data.empty:
|
172 |
print(f"No data found for ticker: {ticker}")
|
173 |
return None
|
|
|
219 |
return prediction_df
|
220 |
|
221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
|
223 |
# --- Streamlit Sidebar Controls ---
|
224 |
with st.sidebar:
|
225 |
st.image("logo2.png", use_container_width=True)
|
226 |
st.markdown("Dashboard Controls")
|
227 |
+
ticker = st.text_input("Stock Ticker", st.session_state.get('last_ticker', "AMZN"), disabled=True).upper()
|
228 |
model_type = st.selectbox(
|
229 |
"Prediction Model",
|
230 |
("Bi-Directional LSTM", "Gated Recurrent Unit (GRU)"),
|
|
|
263 |
else:
|
264 |
st.session_state.data = get_stock_data(ticker)
|
265 |
|
266 |
+
|
267 |
if st.session_state.data is None:
|
268 |
st.session_state.error = f"Could not fetch data for ticker '{ticker}'. It may be an invalid symbol or network issue."
|
269 |
else:
|