File size: 2,296 Bytes
66daf8f
 
2384342
 
66daf8f
2384342
 
66daf8f
 
 
 
9a27f21
66daf8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2384342
 
66daf8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2384342
66daf8f
9a27f21
66daf8f
 
2384342
 
 
 
 
7dd895f
98682dd
7dd895f
31ddb50
 
 
 
 
 
2384342
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import streamlit as st
import pandas as pd
import numpy as np
import joblib

# Load the saved Random Forest model
model = joblib.load('random_forest__solar_insolation_model.pkl')

# Streamlit app
st.title('Solar Insolation Prediction')

# Input fields
air_temp = st.number_input('Air Temperature')
albedo = st.number_input('Albedo')
azimuth = st.number_input('Azimuth')
clearsky_dhi = st.number_input('Clearsky DHI')
clearsky_dni = st.number_input('Clearsky DNI')
clearsky_ghi = st.number_input('Clearsky GHI')
clearsky_gti = st.number_input('Clearsky GTI')
cloud_opacity = st.number_input('Cloud Opacity')
dhi = st.number_input('DHI')
dni = st.number_input('DNI')
ghi = st.number_input('GHI')
gti = st.number_input('GTI')
precipitation_rate = st.number_input('Precipitation Rate')
relative_humidity = st.number_input('Relative Humidity')
zenith = st.number_input('Zenith')

# Collect all inputs into a DataFrame
input_df = pd.DataFrame([{
    'air_temp': air_temp,
    'albedo': albedo,
    'azimuth': azimuth,
    'clearsky_dhi': clearsky_dhi,
    'clearsky_dni': clearsky_dni,
    'clearsky_ghi': clearsky_ghi,
    'clearsky_gti': clearsky_gti,
    'cloud_opacity': cloud_opacity,
    'dhi': dhi,
    'dni': dni,
    'ghi': ghi,
    'gti': gti,
    'precipitation_rate': precipitation_rate,
    'relative_humidity': relative_humidity,
    'zenith': zenith
}])

# Predict button
if st.button('Predict'):
    try:
        # Ensure the input data matches the expected number of features
        expected_features = len(input_df.columns)
        if expected_features != model.n_features_in_:
            st.error(f"Expected {model.n_features_in_} features, but got {expected_features}.")
        else:
            factors_to_check = ['clearsky_dhi', 'clearsky_dni', 'clearsky_ghi', 
                            'clearsky_gti', 'dhi', 'dni', 'ghi', 'gti']
            if input_df[factors_to_check].eq(0).all(axis=None) or input_df.eq(0).all(axis=None):
                st.write('Predicted Solar Insolation:', 0)
            else:
                # Predict solar insolation
                predictions = model.predict(input_df)
                # Display the prediction
                st.write('Predicted Solar Insolation:', predictions[0])
    except Exception as e:
        st.error(f"Error: {e}")