mistermprah commited on
Commit
26547ea
1 Parent(s): 6a782d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -54,10 +54,24 @@ def predict_stock_price(ticker, open_price, high_price, low_price, close_price,
54
  lstm_predictions = lstm_model.predict(x_test_lstm)
55
  lstm_predictions = scaler.inverse_transform(lstm_predictions)
56
  next_day_lstm_price = lstm_predictions[-1][0]
57
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  result = f"Predicted future price for {ticker}: ${next_day_lstm_price:.2f}"
59
 
60
- return result
61
  except Exception as e:
62
  return str(e)
63
 
@@ -89,7 +103,7 @@ iface = gr.Interface(
89
  gr.Number(label="Adj Close"),
90
  gr.Number(label="Volume")
91
  ],
92
- outputs=gr.Textbox(),
93
  title="Stock Price Predictor",
94
  description="Select the stock ticker and input the last recorded values to predict the closing price using the LSTM model."
95
  )
 
54
  lstm_predictions = lstm_model.predict(x_test_lstm)
55
  lstm_predictions = scaler.inverse_transform(lstm_predictions)
56
  next_day_lstm_price = lstm_predictions[-1][0]
57
+
58
+ # Plot the historical data and the predicted future price
59
+ plt.figure(figsize=(12, 6))
60
+ plt.plot(data.index, data['Close'], label='Historical Data')
61
+ plt.axhline(y=next_day_lstm_price, color='g', linestyle='--', label='Predicted Future Price')
62
+ plt.title(f'Historical Stock Price and Predicted Future Price for {ticker}')
63
+ plt.xlabel('Date')
64
+ plt.ylabel('Price (USD)')
65
+ plt.legend()
66
+
67
+ # Save the plot to a file
68
+ plot_filename = 'stock_price_prediction.png'
69
+ plt.savefig(plot_filename)
70
+ plt.close()
71
+
72
  result = f"Predicted future price for {ticker}: ${next_day_lstm_price:.2f}"
73
 
74
+ return result, plot_filename
75
  except Exception as e:
76
  return str(e)
77
 
 
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
  )