Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import joblib | |
| import numpy as np | |
| import pandas as pd | |
| # Load the models | |
| ph_model = joblib.load('random_forest_ph_model.pkl') | |
| tds_model = joblib.load('random_forest_tds_model.pkl') | |
| # Streamlit app title | |
| st.title("TDS and pH Level Predictor") | |
| # Sidebar for user inputs | |
| st.sidebar.header("Input Parameters") | |
| # Collect user inputs for date details | |
| day = st.sidebar.number_input("Day", min_value=1, max_value=31, value=1) | |
| month = st.sidebar.number_input("Month", min_value=1, max_value=12, value=1) | |
| year = st.sidebar.number_input("Year", min_value=2000, max_value=2100, value=2024) | |
| # Prediction button | |
| if st.button("Predict"): | |
| # Generate hourly features | |
| hours = list(range(6, 22)) | |
| day_input = [day] * len(hours) | |
| month_input = [month] * len(hours) | |
| year_input = [year] * len(hours) | |
| # Create feature array for prediction | |
| features = np.array([hours, day_input, month_input, year_input]).T | |
| # Predict pH and TDS values | |
| ph_predictions = ph_model.predict(features) | |
| tds_predictions = tds_model.predict(features) | |
| # Compile results into a DataFrame for better visualization | |
| results_df = pd.DataFrame({ | |
| 'Hour': hours, | |
| 'Predicted pH': ph_predictions, | |
| 'Predicted TDS': tds_predictions | |
| }) | |
| # Display predictions | |
| st.write("### Predictions") | |
| st.dataframe(results_df) | |