Abhisesh7 commited on
Commit
90183f5
·
verified ·
1 Parent(s): e5851b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -6,22 +6,25 @@ from sklearn.preprocessing import MinMaxScaler
6
  from tensorflow import keras
7
 
8
  # Load your trained model
9
- model = keras.models.load_model('your_model.h5')
10
 
11
  # Function to predict stock prices
12
  def predict_stock_price(stock_ticker, start_date, end_date):
13
  # Fetch data
14
  data = yf.download(stock_ticker, start=start_date, end=end_date)
15
 
 
 
 
 
16
  # Preprocess data
17
  scaler = MinMaxScaler()
18
  scaled_data = scaler.fit_transform(data['Close'].values.reshape(-1, 1))
19
-
20
  # Prepare input for the model
21
- # This assumes your model expects a certain shape of input
22
  input_data = scaled_data[-60:] # Use the last 60 days of data
23
  input_data = input_data.reshape((1, input_data.shape[0], 1))
24
-
25
  # Predict stock prices
26
  prediction = model.predict(input_data)
27
  predicted_price = scaler.inverse_transform(prediction) # Rescale back to original price
@@ -30,7 +33,7 @@ def predict_stock_price(stock_ticker, start_date, end_date):
30
 
31
  # Create the Gradio interface
32
  stock_ticker_input = gr.Dropdown(
33
- choices=["AAPL", "GOOGL", "MSFT", "AMZN", "TSLA"],
34
  label="Select Stock Ticker"
35
  )
36
 
@@ -46,7 +49,7 @@ iface = gr.Interface(
46
  ],
47
  outputs="text",
48
  title="Stock Price Prediction App",
49
- description="Enter the stock ticker and date range to predict the stock price."
50
  )
51
 
52
  # Launch the Gradio app
 
6
  from tensorflow import keras
7
 
8
  # Load your trained model
9
+ model = keras.models.load_model('your_model.h5') # Ensure this path is correct
10
 
11
  # Function to predict stock prices
12
  def predict_stock_price(stock_ticker, start_date, end_date):
13
  # Fetch data
14
  data = yf.download(stock_ticker, start=start_date, end=end_date)
15
 
16
+ # Check if data is returned
17
+ if data.empty:
18
+ return "No data available for the selected dates."
19
+
20
  # Preprocess data
21
  scaler = MinMaxScaler()
22
  scaled_data = scaler.fit_transform(data['Close'].values.reshape(-1, 1))
23
+
24
  # Prepare input for the model
 
25
  input_data = scaled_data[-60:] # Use the last 60 days of data
26
  input_data = input_data.reshape((1, input_data.shape[0], 1))
27
+
28
  # Predict stock prices
29
  prediction = model.predict(input_data)
30
  predicted_price = scaler.inverse_transform(prediction) # Rescale back to original price
 
33
 
34
  # Create the Gradio interface
35
  stock_ticker_input = gr.Dropdown(
36
+ choices=["AAPL", "GOOGL", "MSFT", "AMZN", "TSLA"], # Add more tickers as needed
37
  label="Select Stock Ticker"
38
  )
39
 
 
49
  ],
50
  outputs="text",
51
  title="Stock Price Prediction App",
52
+ description="Enter the stock ticker and date range to predict the stock price for tomorrow."
53
  )
54
 
55
  # Launch the Gradio app