Update app.py
Browse files
app.py
CHANGED
@@ -116,4 +116,38 @@ with gr.Blocks() as demo:
|
|
116 |
outputs=[output_text, output_plot]
|
117 |
)
|
118 |
|
119 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
outputs=[output_text, output_plot]
|
117 |
)
|
118 |
|
119 |
+
demo.launch()
|
120 |
+
import matplotlib.pyplot as plt
|
121 |
+
|
122 |
+
def plot_stock_data(ticker, start_date, end_date):
|
123 |
+
# Existing code to fetch stock data and make predictions...
|
124 |
+
stock_data = fetch_data(ticker, start_date, end_date)
|
125 |
+
|
126 |
+
# Assuming you have future_dates and future_prices from your model
|
127 |
+
future_dates = pd.date_range(end_date, periods=90, freq='D') # Example for future dates
|
128 |
+
future_prices = model_predict(stock_data) # Example for predicted prices
|
129 |
+
|
130 |
+
# Check lengths of future_dates and future_prices
|
131 |
+
print(f"Length of future_dates: {len(future_dates)}")
|
132 |
+
print(f"Length of future_prices: {len(future_prices)}")
|
133 |
+
|
134 |
+
# Ensure they are the same length
|
135 |
+
min_length = min(len(future_dates), len(future_prices))
|
136 |
+
future_dates = future_dates[:min_length]
|
137 |
+
future_prices = future_prices[:min_length]
|
138 |
+
|
139 |
+
# Plot historical stock data
|
140 |
+
plt.figure(figsize=(10, 5))
|
141 |
+
plt.plot(stock_data.index, stock_data['Close'], label="Historical Prices")
|
142 |
+
|
143 |
+
# Plot future predicted prices
|
144 |
+
plt.plot(future_dates, future_prices, label="Predicted Future Prices", linestyle='--')
|
145 |
+
|
146 |
+
plt.xlabel("Date")
|
147 |
+
plt.ylabel("Stock Price")
|
148 |
+
plt.title(f"{ticker} Stock Price Prediction")
|
149 |
+
plt.legend()
|
150 |
+
plt.grid(True)
|
151 |
+
|
152 |
+
plt.show()
|
153 |
+
return plt.gcf() # Return the current figure object
|