-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
38 lines (29 loc) · 1.2 KB
/
ui.py
File metadata and controls
38 lines (29 loc) · 1.2 KB
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
import streamlit as st
import pandas as pd
import joblib
# Load trained model
model = joblib.load("travel_time_model.pkl")
# Page title
st.title("Travel Time Prediction System")
st.write("Predict travel time using traffic conditions")
st.divider()
# User Inputs
distance = st.number_input("Distance (in km)", min_value=0.1, value=5.0)
speed = st.number_input("Average Speed (km/h)", min_value=1.0, value=25.0)
time_of_day = st.selectbox("Time of Day",["Morning", "Afternoon", "Evening", "Night"])
traffic_density = st.selectbox("Traffic Density Level", ["Low", "Medium", "High"])
# Encoding
time_of_day_map = {"Morning": 0,"Afternoon": 1,"Evening": 2,"Night": 3}
traffic_density_map = {"Low": 0,"Medium": 1,"High": 2}
# Prediction Button
if st.button("Predict Travel Time"):
input_df = pd.DataFrame([{
"distance_km": distance,
"average_speed_kmph": speed,
"time_of_day": time_of_day_map[time_of_day],
"traffic_density_level": traffic_density_map[traffic_density]
}])
prediction = model.predict(input_df)
st.success(f"Estimated Travel Time: {prediction[0]:.2f} minutes")
st.divider()
st.caption( "Machine Learning Model: Random Forest Regressor | Dataset: Delhi Traffic Data")