Spaces:
Sleeping
Sleeping
mistermprah
commited on
Commit
•
86bd1a4
1
Parent(s):
26547ea
Update app.py
Browse files
app.py
CHANGED
@@ -55,23 +55,25 @@ def predict_stock_price(ticker, open_price, high_price, low_price, close_price,
|
|
55 |
lstm_predictions = scaler.inverse_transform(lstm_predictions)
|
56 |
next_day_lstm_price = lstm_predictions[-1][0]
|
57 |
|
58 |
-
# Plot the
|
59 |
-
plt.figure(figsize=(
|
60 |
-
plt.plot(data.index, data['Close'], label='Historical
|
61 |
-
plt.
|
62 |
-
plt.
|
|
|
63 |
plt.xlabel('Date')
|
64 |
-
plt.ylabel('Price (
|
65 |
plt.legend()
|
66 |
-
|
67 |
-
# Save the plot to a
|
68 |
-
|
69 |
-
plt.savefig(
|
|
|
70 |
plt.close()
|
71 |
|
72 |
result = f"Predicted future price for {ticker}: ${next_day_lstm_price:.2f}"
|
73 |
|
74 |
-
return result,
|
75 |
except Exception as e:
|
76 |
return str(e)
|
77 |
|
@@ -103,7 +105,7 @@ iface = gr.Interface(
|
|
103 |
gr.Number(label="Adj Close"),
|
104 |
gr.Number(label="Volume")
|
105 |
],
|
106 |
-
outputs=[gr.Textbox(),gr.Image()],
|
107 |
title="Stock Price Predictor",
|
108 |
description="Select the stock ticker and input the last recorded values to predict the closing price using the LSTM model."
|
109 |
)
|
|
|
55 |
lstm_predictions = scaler.inverse_transform(lstm_predictions)
|
56 |
next_day_lstm_price = lstm_predictions[-1][0]
|
57 |
|
58 |
+
# Plot the data
|
59 |
+
plt.figure(figsize=(10, 6))
|
60 |
+
plt.plot(data.index, data['Close'], label='Historical Close Prices')
|
61 |
+
plt.axvline(x=data.index[-1], color='r', linestyle='--', label='Prediction Date')
|
62 |
+
plt.plot([data.index[-1], data.index[-1] + pd.DateOffset(1)], [data['Close'].iloc[-1], next_day_lstm_price], 'go-', label='Predicted Price')
|
63 |
+
plt.title(f'Predicted Closing Price for {ticker}')
|
64 |
plt.xlabel('Date')
|
65 |
+
plt.ylabel('Close Price USD ($)')
|
66 |
plt.legend()
|
67 |
+
|
68 |
+
# Save the plot to a buffer
|
69 |
+
buf = io.BytesIO()
|
70 |
+
plt.savefig(buf, format='png')
|
71 |
+
buf.seek(0)
|
72 |
plt.close()
|
73 |
|
74 |
result = f"Predicted future price for {ticker}: ${next_day_lstm_price:.2f}"
|
75 |
|
76 |
+
return result,buf
|
77 |
except Exception as e:
|
78 |
return str(e)
|
79 |
|
|
|
105 |
gr.Number(label="Adj Close"),
|
106 |
gr.Number(label="Volume")
|
107 |
],
|
108 |
+
outputs=[gr.Textbox(), gr.Image(type="plot")],
|
109 |
title="Stock Price Predictor",
|
110 |
description="Select the stock ticker and input the last recorded values to predict the closing price using the LSTM model."
|
111 |
)
|