import streamlit as st import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.svm import SVR from sklearn.metrics import mean_absolute_error st.set_page_config(page_title="ETA Predictor", layout="wide") st.markdown(""" """, unsafe_allow_html=True) st.title("🚗 ETA Predictor") st.markdown("""
This tool estimates travel time between two points in Hyderabad, taking into account variables like weather, traffic, weekday, and time of day. Adjust the values in the sidebar and click the button to get a real-time prediction of your Estimated Time of Arrival (ETA).
""", unsafe_allow_html=True) df = pd.read_csv("hyderabad_eta_data (1).csv") st.sidebar.header("Input Parameters") start_lat = st.sidebar.slider("Start Latitude", -90.0, 90.0, 0.0, 0.1) start_lon = st.sidebar.slider("Start Longitude", -180.0, 180.0, 0.0, 0.1) end_lat = st.sidebar.slider("End Latitude", -90.0, 90.0, 0.0, 0.1) end_lon = st.sidebar.slider("End Longitude", -180.0, 180.0, 0.0, 0.1) distance = st.sidebar.slider("Distance (km)", 0.0, 700.0, 100.0, 1.0) traffic = st.sidebar.selectbox("Traffic Density (1-10)", list(range(1, 11))) weather = st.sidebar.selectbox("Weather", ["rainy", "clear", "foggy"]) week_day = st.sidebar.selectbox("Weekday", ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]) hour = st.sidebar.slider("Hour (0-23)", 0, 23, 0, 1) week_val = {"Sunday": 0, "Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5, "Saturday": 6} weather_map = {"rainy": 0, "clear": 1, "foggy": 2} week = week_val[week_day] weather_val = weather_map[weather] df["weather_condition"] = df["weather_condition"].map(weather_map) X = df.drop("ETA", axis=1) y = df["ETA"] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=23) sv_r = SVR(kernel='rbf', C=100, epsilon=0.1) sv_r.fit(X_train, y_train) y_pred = sv_r.predict(X_test) mae = mean_absolute_error(y_pred, y_test) features = np.array([[start_lat, start_lon, end_lat, end_lon, distance, weather_val, traffic, week, hour]]) estimated_arrival = sv_r.predict(features)[0] st.subheader("Model Performance") st.markdown(f"

Mean Absolute Error: {mae:.2f} hrs

", unsafe_allow_html=True) if st.button("Predict ETA"): st.subheader("Predicted ETA") st.markdown(f"

{estimated_arrival:.2f} hours

", unsafe_allow_html=True)