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') | |
| # Set up the main title and subtitle | |
| st.title("π TDS and pH Level Predictor") | |
| st.markdown("Get predictions for hourly **pH** and **TDS** levels based on selected date. Perfect for water quality monitoring!") | |
| # Sidebar for input parameters with an expander | |
| with st.sidebar.expander("π§ Input Parameters"): | |
| st.write("Enter the date details for which you want to predict the TDS and pH levels.") | |
| day = st.number_input("Day", min_value=1, max_value=31, value=1) | |
| month = st.number_input("Month", min_value=1, max_value=12, value=1) | |
| year = st.number_input("Year", min_value=2000, max_value=2100, value=2024) | |
| # Create a "Predict" button | |
| if st.button("π Predict"): | |
| # Generate hourly features | |
| hours = list(range(6, 22)) # From 6 AM to 10 PM | |
| 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 with a styled table | |
| st.markdown("### π Prediction Results") | |
| st.dataframe(results_df.style.set_properties(**{ | |
| 'background-color': 'lavender', | |
| 'font-size': '14px' | |
| }).highlight_max(axis=0, color='lightblue')) | |