mistermprah commited on
Commit
8ff0005
1 Parent(s): f731195

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -19
app.py CHANGED
@@ -6,8 +6,6 @@ import yfinance as yf
6
  from datetime import datetime
7
  from tensorflow.keras.models import load_model
8
  from joblib import load
9
- import io
10
- from PIL import Image
11
 
12
  # Load the saved LSTM model and scaler
13
  lstm_model = load_model('lstm_model.h5')
@@ -57,27 +55,12 @@ def predict_stock_price(ticker, open_price, high_price, low_price, close_price,
57
  lstm_predictions = scaler.inverse_transform(lstm_predictions)
58
  next_day_lstm_price = lstm_predictions[-1][0]
59
 
60
- # Plot the data
61
- plt.figure(figsize=(10, 6))
62
- plt.plot(data.index, data['Close'], label='Historical Close Prices')
63
- plt.axvline(x=data.index[-1], color='r', linestyle='--', label='Prediction Date')
64
- plt.plot([data.index[-1], data.index[-1] + pd.DateOffset(1)], [data['Close'].iloc[-1], next_day_lstm_price], 'go-', label='Predicted Price')
65
- plt.title(f'Predicted Closing Price for {ticker}')
66
- plt.xlabel('Date')
67
- plt.ylabel('Close Price USD ($)')
68
- plt.legend()
69
-
70
- # Save the plot to a buffer
71
- buf = io.BytesIO()
72
- plt.savefig(buf, format='png')
73
- buf.seek(0)
74
- plt.close()
75
 
76
 
77
 
78
  result = f"Predicted future price for {ticker}: ${next_day_lstm_price:.2f}"
79
 
80
- return result, buf
81
  except Exception as e:
82
  return str(e)
83
 
@@ -109,7 +92,7 @@ iface = gr.Interface(
109
  gr.Number(label="Adj Close"),
110
  gr.Number(label="Volume")
111
  ],
112
- outputs=[gr.Textbox(), gr.Image(type="file")],
113
  title="Stock Price Predictor",
114
  description="Select the stock ticker and input the last recorded values to predict the closing price using the LSTM model."
115
  )
 
6
  from datetime import datetime
7
  from tensorflow.keras.models import load_model
8
  from joblib import load
 
 
9
 
10
  # Load the saved LSTM model and scaler
11
  lstm_model = load_model('lstm_model.h5')
 
55
  lstm_predictions = scaler.inverse_transform(lstm_predictions)
56
  next_day_lstm_price = lstm_predictions[-1][0]
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
 
60
 
61
  result = f"Predicted future price for {ticker}: ${next_day_lstm_price:.2f}"
62
 
63
+ return result
64
  except Exception as e:
65
  return str(e)
66
 
 
92
  gr.Number(label="Adj Close"),
93
  gr.Number(label="Volume")
94
  ],
95
+ outputs=gr.Textbox(),
96
  title="Stock Price Predictor",
97
  description="Select the stock ticker and input the last recorded values to predict the closing price using the LSTM model."
98
  )