Spaces:
Sleeping
Sleeping
| 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}") |