Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
# Import required libraries
|
| 2 |
import yfinance as yf
|
| 3 |
import pandas as pd
|
|
@@ -6,6 +7,7 @@ import tensorflow as tf
|
|
| 6 |
from sklearn.preprocessing import MinMaxScaler
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
import gradio as gr
|
|
|
|
| 9 |
|
| 10 |
# Step 1: Fetch stock data
|
| 11 |
def fetch_stock_data(ticker, start_date, end_date):
|
|
@@ -136,19 +138,23 @@ def plot_predictions(data, predicted_prices, scaler):
|
|
| 136 |
plt.show()
|
| 137 |
|
| 138 |
# Step 7: Gradio Interface Function
|
| 139 |
-
def stock_prediction_app(ticker,
|
| 140 |
"""
|
| 141 |
The core function for the Gradio app. Fetches stock data, trains the LSTM model,
|
| 142 |
predicts future prices, and visualizes the results.
|
| 143 |
|
| 144 |
Args:
|
| 145 |
ticker (str): Stock ticker symbol selected by the user.
|
| 146 |
-
|
| 147 |
-
|
| 148 |
|
| 149 |
Returns:
|
| 150 |
None (Displays a plot of historical and predicted stock prices).
|
| 151 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# Fetch stock data
|
| 153 |
data = fetch_stock_data(ticker, start_date, end_date)
|
| 154 |
|
|
@@ -173,8 +179,8 @@ ui = gr.Interface(
|
|
| 173 |
fn=stock_prediction_app,
|
| 174 |
inputs=[
|
| 175 |
gr.Dropdown(tickers, label="Select Stock Ticker"),
|
| 176 |
-
gr.
|
| 177 |
-
gr.
|
| 178 |
],
|
| 179 |
outputs="plot",
|
| 180 |
title="Stock Prediction App",
|
|
|
|
| 1 |
+
|
| 2 |
# Import required libraries
|
| 3 |
import yfinance as yf
|
| 4 |
import pandas as pd
|
|
|
|
| 7 |
from sklearn.preprocessing import MinMaxScaler
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
import gradio as gr
|
| 10 |
+
from datetime import datetime
|
| 11 |
|
| 12 |
# Step 1: Fetch stock data
|
| 13 |
def fetch_stock_data(ticker, start_date, end_date):
|
|
|
|
| 138 |
plt.show()
|
| 139 |
|
| 140 |
# Step 7: Gradio Interface Function
|
| 141 |
+
def stock_prediction_app(ticker, start_date_str, end_date_str):
|
| 142 |
"""
|
| 143 |
The core function for the Gradio app. Fetches stock data, trains the LSTM model,
|
| 144 |
predicts future prices, and visualizes the results.
|
| 145 |
|
| 146 |
Args:
|
| 147 |
ticker (str): Stock ticker symbol selected by the user.
|
| 148 |
+
start_date_str (str): Start date selected by the user (YYYY-MM-DD).
|
| 149 |
+
end_date_str (str): End date selected by the user (YYYY-MM-DD).
|
| 150 |
|
| 151 |
Returns:
|
| 152 |
None (Displays a plot of historical and predicted stock prices).
|
| 153 |
"""
|
| 154 |
+
# Convert date strings to datetime objects
|
| 155 |
+
start_date = datetime.strptime(start_date_str, "%Y-%m-%d").date()
|
| 156 |
+
end_date = datetime.strptime(end_date_str, "%Y-%m-%d").date()
|
| 157 |
+
|
| 158 |
# Fetch stock data
|
| 159 |
data = fetch_stock_data(ticker, start_date, end_date)
|
| 160 |
|
|
|
|
| 179 |
fn=stock_prediction_app,
|
| 180 |
inputs=[
|
| 181 |
gr.Dropdown(tickers, label="Select Stock Ticker"),
|
| 182 |
+
gr.Textbox(label="Start Date (YYYY-MM-DD)"), # Use textbox instead
|
| 183 |
+
gr.Textbox(label="End Date (YYYY-MM-DD)") # Use textbox instead
|
| 184 |
],
|
| 185 |
outputs="plot",
|
| 186 |
title="Stock Prediction App",
|