File size: 3,127 Bytes
7b566f1
 
 
787860e
7b566f1
 
 
 
e73edec
787860e
e73edec
cd44e6c
 
 
 
 
7b566f1
36725ac
7b566f1
36725ac
cd44e6c
7b566f1
36725ac
1363fb9
cd44e6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b566f1
36725ac
7b566f1
 
 
cd44e6c
7b566f1
 
 
36725ac
 
 
 
 
cd44e6c
 
 
 
 
 
 
 
 
 
 
36725ac
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.losses import MeanSquaredError
import joblib

@st.cache_resource
def load_resources():
    custom_objects = {
        'mse': MeanSquaredError()
    }
    model = load_model('bike_model.h5', custom_objects=custom_objects)
    scaler_x = joblib.load('scaler_x.pkl')
    scaler_y = joblib.load('scaler_y.pkl')
    features = np.load('feature_names.npy', allow_pickle=True)
    return model, scaler_x, scaler_y, features
st.title('🚲 Bike Sharing Demand Predictor')
st.write('Predict hourly bike rental demand based on weather conditions and time features.')

try:
    model, scaler_x, scaler_y, feature_names = load_resources()

    col1, col2 = st.columns(2)
    
    with col1:
        # Categorical inputs
        season = st.selectbox('season', options=[1, 2, 3, 4], 
                            help='1:Spring, 2:Summer, 3:Fall, 4:Winter')
        
        holiday = st.selectbox('holiday', options=[0, 1],
                             help='0:No, 1:Yes')
        
        workingday = st.selectbox('workingday', options=[0, 1],
                                 help='0:No, 1:Yes')
        
        weather = st.selectbox('weather', options=[1, 2, 3, 4],
                             help='1:Clear, 2:Mist, 3:Light Rain/Snow, 4:Heavy Rain')

    with col2:
        # Continuous inputs with sliders
        temp = st.slider('temp (°C)', min_value=0.82, max_value=41.0, 
                        value=20.0, step=0.1)
        
        atemp = st.slider('feels like temp', min_value=0.76, max_value=45.5, 
                         value=23.7, step=0.1)
        
        humidity = st.slider('humidity (%)', min_value=0, max_value=100, 
                           value=62)
        
        windspeed = st.slider('windspeed', min_value=0.0, max_value=57.0, 
                            value=13.0, step=0.1)

    # Create input dictionary
    inputs = {
        'season': season,
        'holiday': holiday,
        'workingday': workingday,
        'weather': weather,
        'temp': temp,
        'atemp': atemp,
        'humidity': humidity,
        'windspeed': windspeed
    }

    if st.button('Predict Demand', use_container_width=True):
        x = scaler_x.transform(np.array(list(inputs.values())).reshape(1, -1))
        x = x.reshape(1, 1, x.shape[1])
        
        pred_scaled = model.predict(x, verbose=0)
        pred = scaler_y.inverse_transform(pred_scaled)[0][0]
        
        st.success(f'Predicted demand: {max(0, int(pred))} bikes')

except Exception as e:
    st.error(f'Error: {str(e)}')

st.markdown('---')
st.markdown("""
### Feature Information:
- **season**: 1=Spring, 2=Summer, 3=Fall, 4=Winter
- **holiday**: 0=No, 1=Yes
- **workingday**: 0=No, 1=Yes
- **weather**: 1=Clear, 2=Mist, 3=Light Rain/Snow, 4=Heavy Rain
- **temp**: Temperature in Celsius (0.82°C to 41°C)
- **atemp**: "Feels like" temperature (0.76°C to 45.5°C)
- **humidity**: Relative humidity (0% to 100%)
- **windspeed**: Wind speed (0 to 57)
""")
st.markdown('Made with ❤️ using Streamlit and TensorFlow')