File size: 1,367 Bytes
7f1091b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)