Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,14 @@ from joblib import load
|
|
10 |
lstm_model = load_model('lstm_model.h5')
|
11 |
scaler = load('scaler.joblib')
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Function to get the last row of stock data
|
17 |
def get_last_stock_data(ticker):
|
@@ -109,35 +115,47 @@ def display_historical_data(ticker):
|
|
109 |
start_date = '2010-01-01'
|
110 |
end_date = datetime.now().strftime('%Y-%m-%d')
|
111 |
data = yf.download(ticker, start=start_date, end=end_date)
|
112 |
-
return data.tail(30)
|
113 |
except Exception as e:
|
114 |
return str(e)
|
115 |
|
116 |
# Streamlit interface
|
117 |
st.title("Stockstream")
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
tab1, tab2, tab3 = st.tabs(["Today's Price", "Next Month's Price", "Historical Data"])
|
120 |
|
121 |
with tab1:
|
122 |
st.header("Today's Price")
|
123 |
-
ticker_input = st.selectbox("Stock Ticker",
|
124 |
open_price = st.number_input("Open Price", value=0.0, key="today_open_price")
|
125 |
close_price = st.number_input("Close Price", value=0.0, key="today_close_price")
|
126 |
if st.button("Predict Today's Price"):
|
127 |
-
|
|
|
128 |
st.write(result)
|
129 |
|
130 |
with tab2:
|
131 |
st.header("Next Month's Price")
|
132 |
-
next_month_ticker_input = st.selectbox("Stock Ticker",
|
133 |
next_month_close_price = st.number_input("Close Price", value=0.0, key="next_month_close_price")
|
134 |
if st.button("Predict Next Month's Price"):
|
135 |
-
|
|
|
136 |
st.write(result)
|
137 |
|
138 |
with tab3:
|
139 |
st.header("Historical Data")
|
140 |
-
historical_ticker_input = st.selectbox("Stock Ticker",
|
141 |
if st.button("View Data"):
|
142 |
-
|
|
|
143 |
st.dataframe(data)
|
|
|
10 |
lstm_model = load_model('lstm_model.h5')
|
11 |
scaler = load('scaler.joblib')
|
12 |
|
13 |
+
# Dictionary of stock tickers and their full names
|
14 |
+
stock_dict = {
|
15 |
+
'GOOG': 'Alphabet Inc.',
|
16 |
+
'AAPL': 'Apple Inc.',
|
17 |
+
'TSLA': 'Tesla, Inc.',
|
18 |
+
'AMZN': 'Amazon.com, Inc.',
|
19 |
+
'MSFT': 'Microsoft Corporation'
|
20 |
+
}
|
21 |
|
22 |
# Function to get the last row of stock data
|
23 |
def get_last_stock_data(ticker):
|
|
|
115 |
start_date = '2010-01-01'
|
116 |
end_date = datetime.now().strftime('%Y-%m-%d')
|
117 |
data = yf.download(ticker, start=start_date, end=end_date)
|
118 |
+
return data.tail(30).iloc[::-1] # Reverse to have the latest date on top
|
119 |
except Exception as e:
|
120 |
return str(e)
|
121 |
|
122 |
# Streamlit interface
|
123 |
st.title("Stockstream")
|
124 |
|
125 |
+
# Sidebar for adding new stocks
|
126 |
+
st.sidebar.header("Add a New Stock Ticker")
|
127 |
+
new_ticker = st.sidebar.text_input("Stock Ticker", value="")
|
128 |
+
new_full_name = st.sidebar.text_input("Full Name", value="")
|
129 |
+
if st.sidebar.button("Add Stock Ticker"):
|
130 |
+
if new_ticker and new_full_name:
|
131 |
+
stock_dict[new_ticker.upper()] = new_full_name
|
132 |
+
|
133 |
+
# Tabs for different functionalities
|
134 |
tab1, tab2, tab3 = st.tabs(["Today's Price", "Next Month's Price", "Historical Data"])
|
135 |
|
136 |
with tab1:
|
137 |
st.header("Today's Price")
|
138 |
+
ticker_input = st.selectbox("Stock Ticker", [f"{key} - {value}" for key, value in stock_dict.items()], key="today_ticker")
|
139 |
open_price = st.number_input("Open Price", value=0.0, key="today_open_price")
|
140 |
close_price = st.number_input("Close Price", value=0.0, key="today_close_price")
|
141 |
if st.button("Predict Today's Price"):
|
142 |
+
ticker = ticker_input.split(' - ')[0]
|
143 |
+
result = predict_stock_price(ticker, open_price, close_price)
|
144 |
st.write(result)
|
145 |
|
146 |
with tab2:
|
147 |
st.header("Next Month's Price")
|
148 |
+
next_month_ticker_input = st.selectbox("Stock Ticker", [f"{key} - {value}" for key, value in stock_dict.items()], key="next_month_ticker")
|
149 |
next_month_close_price = st.number_input("Close Price", value=0.0, key="next_month_close_price")
|
150 |
if st.button("Predict Next Month's Price"):
|
151 |
+
ticker = next_month_ticker_input.split(' - ')[0]
|
152 |
+
result = predict_next_month_price(ticker, next_month_close_price)
|
153 |
st.write(result)
|
154 |
|
155 |
with tab3:
|
156 |
st.header("Historical Data")
|
157 |
+
historical_ticker_input = st.selectbox("Stock Ticker", [f"{key} - {value}" for key, value in stock_dict.items()], key="historical_ticker")
|
158 |
if st.button("View Data"):
|
159 |
+
ticker = historical_ticker_input.split(' - ')[0]
|
160 |
+
data = display_historical_data(ticker)
|
161 |
st.dataframe(data)
|