Spaces:
Sleeping
Sleeping
mistermprah
commited on
Commit
•
2d3ea73
1
Parent(s):
117f2f8
Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,7 @@ def predict_stock_price(ticker, open_price, close_price):
|
|
61 |
return str(e)
|
62 |
|
63 |
# Function to predict next month's price
|
64 |
-
def predict_next_month_price(ticker):
|
65 |
try:
|
66 |
start_date = '2010-01-01'
|
67 |
end_date = datetime.now().strftime('%Y-%m-%d')
|
@@ -72,6 +72,11 @@ def predict_next_month_price(ticker):
|
|
72 |
dataset = data.values
|
73 |
scaled_data = scaler.transform(dataset)
|
74 |
|
|
|
|
|
|
|
|
|
|
|
75 |
# Prepare the data for LSTM
|
76 |
x_test_lstm = []
|
77 |
for i in range(60, len(scaled_data)):
|
@@ -85,8 +90,8 @@ def predict_next_month_price(ticker):
|
|
85 |
for _ in range(30):
|
86 |
pred = lstm_model.predict(x_test_lstm[-1].reshape(1, 60, 1))
|
87 |
predictions.append(pred[0])
|
88 |
-
|
89 |
-
x_test_lstm = x_test_lstm
|
90 |
|
91 |
predictions = np.array(predictions)
|
92 |
next_month_predictions = scaler.inverse_transform(predictions)
|
@@ -122,9 +127,10 @@ with gr.Blocks() as app:
|
|
122 |
with gr.Tab("Predict Next Month's Price"):
|
123 |
gr.Markdown("## Predict Next Month's Price")
|
124 |
next_month_ticker_input = gr.Dropdown(choices=stock_list, label="Stock Ticker")
|
|
|
125 |
next_month_predict_button = gr.Button("Predict")
|
126 |
next_month_predict_output = gr.Textbox()
|
127 |
-
next_month_predict_button.click(predict_next_month_price, inputs=[next_month_ticker_input], outputs=next_month_predict_output)
|
128 |
|
129 |
with gr.Tab("View Historical Data"):
|
130 |
gr.Markdown("## View Historical Data")
|
|
|
61 |
return str(e)
|
62 |
|
63 |
# Function to predict next month's price
|
64 |
+
def predict_next_month_price(ticker, close_price):
|
65 |
try:
|
66 |
start_date = '2010-01-01'
|
67 |
end_date = datetime.now().strftime('%Y-%m-%d')
|
|
|
72 |
dataset = data.values
|
73 |
scaled_data = scaler.transform(dataset)
|
74 |
|
75 |
+
# Append the user inputs as the last row in the data
|
76 |
+
user_input = np.array([[close_price]])
|
77 |
+
user_input_scaled = scaler.transform(user_input)
|
78 |
+
scaled_data = np.vstack([scaled_data, user_input_scaled])
|
79 |
+
|
80 |
# Prepare the data for LSTM
|
81 |
x_test_lstm = []
|
82 |
for i in range(60, len(scaled_data)):
|
|
|
90 |
for _ in range(30):
|
91 |
pred = lstm_model.predict(x_test_lstm[-1].reshape(1, 60, 1))
|
92 |
predictions.append(pred[0])
|
93 |
+
new_input = np.append(x_test_lstm[-1][1:], pred)
|
94 |
+
x_test_lstm = np.append(x_test_lstm, new_input.reshape(1, 60, 1), axis=0)
|
95 |
|
96 |
predictions = np.array(predictions)
|
97 |
next_month_predictions = scaler.inverse_transform(predictions)
|
|
|
127 |
with gr.Tab("Predict Next Month's Price"):
|
128 |
gr.Markdown("## Predict Next Month's Price")
|
129 |
next_month_ticker_input = gr.Dropdown(choices=stock_list, label="Stock Ticker")
|
130 |
+
next_month_close_price = gr.Number(label="Close")
|
131 |
next_month_predict_button = gr.Button("Predict")
|
132 |
next_month_predict_output = gr.Textbox()
|
133 |
+
next_month_predict_button.click(predict_next_month_price, inputs=[next_month_ticker_input, next_month_close_price], outputs=next_month_predict_output)
|
134 |
|
135 |
with gr.Tab("View Historical Data"):
|
136 |
gr.Markdown("## View Historical Data")
|