mistermprah commited on
Commit
86bd1a4
1 Parent(s): 26547ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
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 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,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
  )