Update app.py
Browse files35 unmodified lines36373839404142306 unmodified lines3493503513523533543551 unmodified line35735835936036136212 unmodified lines37537637737837938038110 unmodified lines3923933943953963973984 unmodified lines4034044054064074088 unmodified lines41741841942042142242315 unmodified lines43944044144244344444535 unmodified lines]class StockPredictor:def __init__(self, data, model_type):self.data = dataself.model_type = model_typeself.model = None306 unmodified linespredict_stock_prices()def test_model():st.header("Test Prophet Model")col1, col2 = st.columns(2)1 unmodified linecompany = st.selectbox("Select Company", [company for company, _ in COMPANIES])test_split = st.slider("Test Data Split", 0.1, 0.5, 0.2, 0.05)if st.button("Train and Test Model"):with st.spinner("Fetching data and training model..."):company_name, ticker = next((name, symbol) for name, symbol in COMPANIES if name == company)12 unmodified linestrain_data = data.iloc[:split_index]test_data = data.iloc[split_index:]predictor = StockPredictor(train_data) # Updated: removed model_type argumentpredictor.preprocess_data()if predictor.train_model():test_pred = predictor.predict(days=len(test_data))10 unmodified linesplot = create_test_plot(predictor.data, test_data, test_pred, company_name)st.plotly_chart(plot, use_container_width=True)else:st.error("Failed to train the Prophet model. Please try a different dataset.")def predict_stock_prices():st.header("Predict Stock Prices")4 unmodified linescompany = st.selectbox("Select Company", [company for company, _ in COMPANIES])days_to_predict = st.slider("Days to Predict", 1, 365, 30)if st.button("Predict Stock Prices"):with st.spinner("Fetching data and making predictions..."):company_name, ticker = next((name, symbol) for name, symbol in COMPANIES if name == company)8 unmodified linesst.markdown(get_table_download_link(data), unsafe_allow_html=True)predictor = StockPredictor(data) # Updated: removed model_type argumentpredictor.preprocess_data()if predictor.train_model():predictions = predictor.predict(days=days_to_predict)15 unmodified linesfor item in news:st.markdown(f"[{item['title']}]({item['link']}) ({item['pubDate']})")else:st.error("Failed to train the Prophet model. Please try a different dataset.")def explore_data():st.header("Explore Stock Data")35 unmodified lines36373839404142306 unmodified lines3493503513523533543551 unmodified line35735835936036136236336436512 unmodified lines37837938038138238338410 unmodified lines3953963973983994004014 unmodified lines4064074084094104114124134148 unmodified lines42342442542642742842915 unmodified lines44544644744844945045135 unmodified lines]class StockPredictor:def __init__(self, data, model_type='Prophet'):self.data = dataself.model_type = model_typeself.model = None306 unmodified linespredict_stock_prices()def test_model():st.header("Test Stock Prediction Model")col1, col2 = st.columns(2)1 unmodified linecompany = st.selectbox("Select Company", [company for company, _ in COMPANIES])test_split = st.slider("Test Data Split", 0.1, 0.5, 0.2, 0.05)with col2:model_type = st.selectbox("Select Model Type", ['Prophet', 'LSTM', 'SARIMA', 'XGBoost', 'RandomForest'])if st.button("Train and Test Model"):with st.spinner("Fetching data and training model..."):company_name, ticker = next((name, symbol) for name, symbol in COMPANIES if name == company)12 unmodified linestrain_data = data.iloc[:split_index]test_data = data.iloc[split_index:]predictor = StockPredictor(train_data, model_type) # Updated: added model_type argumentpredictor.preprocess_data()if predictor.train_model():test_pred = predictor.predict(days=len(test_data))10 unmodified linesplot = create_test_plot(predictor.data, test_data, test_pred, company_name)st.plotly_chart(plot, use_container_width=True)else:st.error(f"Failed to train the {model_type} model. Please try a different dataset or model type.")def predict_stock_prices():st.header("Predict Stock Prices")4 unmodified linescompany = st.selectbox("Select Company", [company for company, _ in COMPANIES])days_to_predict = st.slider("Days to Predict", 1, 365, 30)with col2:model_type = st.selectbox("Select Model Type", ['Prophet', 'LSTM', 'SARIMA', 'XGBoost', 'RandomForest'])if st.button("Predict Stock Prices"):with st.spinner("Fetching data and making predictions..."):company_name, ticker = next((name, symbol) for name, symbol in COMPANIES if name == company)8 unmodified linesst.markdown(get_table_download_link(data), unsafe_allow_html=True)predictor = StockPredictor(data, model_type) # Updated: added model_type argumentpredictor.preprocess_data()if predictor.train_model():predictions = predictor.predict(days=days_to_predict)15 unmodified linesfor item in news:st.markdown(f"[{item['title']}]({item['link']}) ({item['pubDate']})")else:st.error(f"Failed to train the {model_type} model. Please try a different dataset or model type.")def explore_data():st.header("Explore Stock Data")
app.py+12-6