File size: 1,725 Bytes
62424e6
84cc777
62424e6
c558b11
edde84b
62424e6
f2f0925
62424e6
90183f5
62424e6
 
 
 
 
 
90183f5
 
 
 
62424e6
 
 
90183f5
62424e6
 
 
90183f5
62424e6
 
 
 
 
971d03b
edde84b
62424e6
90183f5
edde84b
c558b11
84cc777
62424e6
 
 
 
 
 
 
 
 
 
edde84b
62424e6
90183f5
62424e6
 
 
253645c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
import pandas as pd
import numpy as np
import yfinance as yf
from sklearn.preprocessing import MinMaxScaler
from tensorflow import keras

# Load your trained model
model = keras.models.load_model('your_model.h5')  # Ensure this path is correct

# Function to predict stock prices
def predict_stock_price(stock_ticker, start_date, end_date):
    # Fetch data
    data = yf.download(stock_ticker, start=start_date, end=end_date)
    
    # Check if data is returned
    if data.empty:
        return "No data available for the selected dates."

    # Preprocess data
    scaler = MinMaxScaler()
    scaled_data = scaler.fit_transform(data['Close'].values.reshape(-1, 1))

    # Prepare input for the model
    input_data = scaled_data[-60:]  # Use the last 60 days of data
    input_data = input_data.reshape((1, input_data.shape[0], 1))

    # Predict stock prices
    prediction = model.predict(input_data)
    predicted_price = scaler.inverse_transform(prediction)  # Rescale back to original price
    
    return f"Predicted stock price for tomorrow: ${predicted_price[0][0]:.2f}"

# Create the Gradio interface
stock_ticker_input = gr.Dropdown(
    choices=["AAPL", "GOOGL", "MSFT", "AMZN", "TSLA"],  # Add more tickers as needed
    label="Select Stock Ticker"
)

start_date_input = gr.Date(label="Start Date")
end_date_input = gr.Date(label="End Date")

iface = gr.Interface(
    fn=predict_stock_price,
    inputs=[
        stock_ticker_input,
        start_date_input,
        end_date_input
    ],
    outputs="text",
    title="Stock Price Prediction App",
    description="Enter the stock ticker and date range to predict the stock price for tomorrow."
)

# Launch the Gradio app
iface.launch()