Update app.py
Browse files
app.py
CHANGED
@@ -279,12 +279,14 @@ def fetch_news(company_name):
|
|
279 |
st.error(f"Error fetching news: {str(e)}")
|
280 |
return []
|
281 |
|
282 |
-
def get_table_download_link(df):
|
|
|
283 |
csv = df.to_csv(index=False)
|
284 |
b64 = base64.b64encode(csv.encode()).decode()
|
285 |
-
href = f'<a href="data:file/csv;base64,{b64}" download="
|
286 |
return href
|
287 |
|
|
|
288 |
def main():
|
289 |
st.set_page_config(page_title="Stock Price Predictor", layout="wide")
|
290 |
st.title("Advanced Stock Price Predictor using Prophet")
|
@@ -316,7 +318,13 @@ def test_model():
|
|
316 |
st.subheader("Stock Data Information")
|
317 |
st.write(data.info())
|
318 |
st.write(data.describe())
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
|
321 |
split_index = int(len(data) * (1 - test_split))
|
322 |
train_data = data.iloc[:split_index]
|
@@ -344,7 +352,12 @@ def test_model():
|
|
344 |
# Cross-validation results
|
345 |
st.subheader("Cross-Validation Results")
|
346 |
cv_results = predictor.cross_validate_model()
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
# Calculate and display average metrics
|
350 |
avg_mse = cv_results['mse'].mean()
|
@@ -355,12 +368,19 @@ def test_model():
|
|
355 |
st.write(f"Average RMSE: {avg_rmse:.4f}")
|
356 |
st.write(f"Average MAPE: {avg_mape:.4f}")
|
357 |
|
358 |
-
#
|
359 |
-
st.subheader("
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
else:
|
365 |
st.error("Failed to evaluate the model. The evaluation metrics are None.")
|
366 |
else:
|
@@ -368,7 +388,7 @@ def test_model():
|
|
368 |
else:
|
369 |
st.error("Failed to train the Prophet model. Please try a different dataset.")
|
370 |
else:
|
371 |
-
st.error("Failed to fetch stock data. Please try again."
|
372 |
|
373 |
def predict_stock_prices():
|
374 |
st.header("Predict Stock Prices with Enhanced Model")
|
|
|
279 |
st.error(f"Error fetching news: {str(e)}")
|
280 |
return []
|
281 |
|
282 |
+
def get_table_download_link(df, filename, text):
|
283 |
+
"""Generates a link to download the given dataframe as a CSV file."""
|
284 |
csv = df.to_csv(index=False)
|
285 |
b64 = base64.b64encode(csv.encode()).decode()
|
286 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="{filename}">{text}</a>'
|
287 |
return href
|
288 |
|
289 |
+
|
290 |
def main():
|
291 |
st.set_page_config(page_title="Stock Price Predictor", layout="wide")
|
292 |
st.title("Advanced Stock Price Predictor using Prophet")
|
|
|
318 |
st.subheader("Stock Data Information")
|
319 |
st.write(data.info())
|
320 |
st.write(data.describe())
|
321 |
+
|
322 |
+
# Display interactive dataframe
|
323 |
+
st.subheader("Stock Data Preview")
|
324 |
+
st.dataframe(data.head(100), use_container_width=True)
|
325 |
+
|
326 |
+
# Provide download link for full dataset
|
327 |
+
st.markdown(get_table_download_link(data, f"{ticker}_stock_data.csv", "Download full stock data CSV"), unsafe_allow_html=True)
|
328 |
|
329 |
split_index = int(len(data) * (1 - test_split))
|
330 |
train_data = data.iloc[:split_index]
|
|
|
352 |
# Cross-validation results
|
353 |
st.subheader("Cross-Validation Results")
|
354 |
cv_results = predictor.cross_validate_model()
|
355 |
+
|
356 |
+
# Display interactive dataframe
|
357 |
+
st.dataframe(cv_results, use_container_width=True)
|
358 |
+
|
359 |
+
# Provide download link for cross-validation results
|
360 |
+
st.markdown(get_table_download_link(cv_results, f"{ticker}_cv_results.csv", "Download cross-validation results CSV"), unsafe_allow_html=True)
|
361 |
|
362 |
# Calculate and display average metrics
|
363 |
avg_mse = cv_results['mse'].mean()
|
|
|
368 |
st.write(f"Average RMSE: {avg_rmse:.4f}")
|
369 |
st.write(f"Average MAPE: {avg_mape:.4f}")
|
370 |
|
371 |
+
# Display predictions
|
372 |
+
st.subheader("Predictions")
|
373 |
+
predictions_df = pd.DataFrame({
|
374 |
+
'Date': test_pred['ds'],
|
375 |
+
'Predicted': test_pred['yhat'],
|
376 |
+
'Lower Bound': test_pred['yhat_lower'],
|
377 |
+
'Upper Bound': test_pred['yhat_upper']
|
378 |
+
})
|
379 |
+
st.dataframe(predictions_df, use_container_width=True)
|
380 |
+
|
381 |
+
# Provide download link for predictions
|
382 |
+
st.markdown(get_table_download_link(predictions_df, f"{ticker}_predictions.csv", "Download predictions CSV"), unsafe_allow_html=True)
|
383 |
+
|
384 |
else:
|
385 |
st.error("Failed to evaluate the model. The evaluation metrics are None.")
|
386 |
else:
|
|
|
388 |
else:
|
389 |
st.error("Failed to train the Prophet model. Please try a different dataset.")
|
390 |
else:
|
391 |
+
st.error("Failed to fetch stock data. Please try again."
|
392 |
|
393 |
def predict_stock_prices():
|
394 |
st.header("Predict Stock Prices with Enhanced Model")
|