Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +74 -0
- hyderabad_eta_data (1).csv +0 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sklearn.model_selection import train_test_split
|
| 5 |
+
from sklearn.svm import SVR
|
| 6 |
+
from sklearn.metrics import mean_absolute_error
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="ETA Predictor", layout="wide")
|
| 9 |
+
|
| 10 |
+
st.markdown("""
|
| 11 |
+
<style>
|
| 12 |
+
.css-1cypcdb, .css-1p05t8e {
|
| 13 |
+
font-size: 11px !important;
|
| 14 |
+
color: #2f4f4f !important;
|
| 15 |
+
}
|
| 16 |
+
section[data-testid="stSidebar"] {
|
| 17 |
+
background-color: #f0f2f6;
|
| 18 |
+
}
|
| 19 |
+
h1 {
|
| 20 |
+
font-size: 20px;
|
| 21 |
+
color: #003366;
|
| 22 |
+
}
|
| 23 |
+
h3 {
|
| 24 |
+
font-size: 14px;
|
| 25 |
+
color: #cc6600;
|
| 26 |
+
}
|
| 27 |
+
</style>
|
| 28 |
+
""", unsafe_allow_html=True)
|
| 29 |
+
|
| 30 |
+
st.title("🚗 ETA Predictor")
|
| 31 |
+
st.markdown("""
|
| 32 |
+
<h5>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).</h5>
|
| 33 |
+
""", unsafe_allow_html=True)
|
| 34 |
+
|
| 35 |
+
df = pd.read_csv("hyderabad_eta_data (1).csv")
|
| 36 |
+
|
| 37 |
+
st.sidebar.header("Input Parameters")
|
| 38 |
+
|
| 39 |
+
start_lat = st.sidebar.slider("Start Latitude", -90.0, 90.0, 0.0, 0.1)
|
| 40 |
+
start_lon = st.sidebar.slider("Start Longitude", -180.0, 180.0, 0.0, 0.1)
|
| 41 |
+
end_lat = st.sidebar.slider("End Latitude", -90.0, 90.0, 0.0, 0.1)
|
| 42 |
+
end_lon = st.sidebar.slider("End Longitude", -180.0, 180.0, 0.0, 0.1)
|
| 43 |
+
distance = st.sidebar.slider("Distance (km)", 0.0, 700.0, 100.0, 1.0)
|
| 44 |
+
|
| 45 |
+
traffic = st.sidebar.selectbox("Traffic Density (1-10)", list(range(1, 11)))
|
| 46 |
+
weather = st.sidebar.selectbox("Weather", ["rainy", "clear", "foggy"])
|
| 47 |
+
week_day = st.sidebar.selectbox("Weekday", ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"])
|
| 48 |
+
hour = st.sidebar.slider("Hour (0-23)", 0, 23, 0, 1)
|
| 49 |
+
|
| 50 |
+
week_val = {"Sunday": 0, "Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5, "Saturday": 6}
|
| 51 |
+
weather_map = {"rainy": 0, "clear": 1, "foggy": 2}
|
| 52 |
+
|
| 53 |
+
week = week_val[week_day]
|
| 54 |
+
weather_val = weather_map[weather]
|
| 55 |
+
|
| 56 |
+
df["weather_condition"] = df["weather_condition"].map(weather_map)
|
| 57 |
+
X = df.drop("ETA", axis=1)
|
| 58 |
+
y = df["ETA"]
|
| 59 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=23)
|
| 60 |
+
|
| 61 |
+
sv_r = SVR(kernel='rbf', C=100, epsilon=0.1)
|
| 62 |
+
sv_r.fit(X_train, y_train)
|
| 63 |
+
y_pred = sv_r.predict(X_test)
|
| 64 |
+
mae = mean_absolute_error(y_pred, y_test)
|
| 65 |
+
|
| 66 |
+
features = np.array([[start_lat, start_lon, end_lat, end_lon, distance, weather_val, traffic, week, hour]])
|
| 67 |
+
estimated_arrival = sv_r.predict(features)[0]
|
| 68 |
+
|
| 69 |
+
st.subheader("Model Performance")
|
| 70 |
+
st.markdown(f"<p style='font-size:12px;'>Mean Absolute Error: <b>{mae:.2f} hrs</b></p>", unsafe_allow_html=True)
|
| 71 |
+
|
| 72 |
+
if st.button("Predict ETA"):
|
| 73 |
+
st.subheader("Predicted ETA")
|
| 74 |
+
st.markdown(f"<h2 style='color:brown; font-size:20px;'><strong>{estimated_arrival:.2f} hours</strong></h2>", unsafe_allow_html=True)
|
hyderabad_eta_data (1).csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
scikit-learn
|