File size: 3,595 Bytes
bc0bf38 | 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | import streamlit as st
import pandas as pd
import pickle
# ---------------- PAGE CONFIG ----------------
st.set_page_config(
page_title="Swiggy Delivery Prediction",
page_icon="π΅",
layout="wide"
)
# ---------------- CUSTOM CSS ----------------
st.markdown("""
<style>
.main {
background-color: #f5f7fa;
}
.title {
text-align: center;
font-size: 40px;
font-weight: bold;
color: #fc8019;
}
.subtext {
text-align: center;
font-size: 18px;
color: gray;
margin-bottom: 30px;
}
.prediction-box {
background-color: #ffffff;
padding: 30px;
border-radius: 15px;
box-shadow: 0px 4px 15px rgba(0,0,0,0.1);
text-align: center;
}
</style>
""", unsafe_allow_html=True)
# ---------------- LOAD MODEL ----------------
with open("model.pkl", "rb") as file:
Model = pickle.load(file)
# ---------------- TITLE ----------------
st.markdown('<div class="title">π΅ Swiggy Delivery Time Prediction</div>', unsafe_allow_html=True)
st.markdown('<div class="subtext">Predict food delivery time instantly using Machine Learning</div>', unsafe_allow_html=True)
# ---------------- LAYOUT ----------------
col1, col2 = st.columns(2)
with col1:
st.subheader("π Delivery Partner Details")
age = st.number_input("Age", 18, 60, 25)
ratings = st.number_input("Ratings", 1.0, 5.0, 4.5)
vehicle_condition = st.selectbox("Vehicle Condition", [0,1,2,3])
multiple_deliveries = st.selectbox("Multiple Deliveries", [0,1,2,3,4,5])
with col2:
st.subheader("π Order Details")
distance = st.number_input("Distance (km)", 0.0, 30.0, 5.0)
order_time_hour = st.selectbox("Order Time Hour", list(range(24)))
traffic = st.selectbox("Traffic", ["Low","Medium","High","Jam"])
festival = st.selectbox("Festival", ["No","Yes"])
weather = st.selectbox("Weather", ["Sunny","Cloudy","Fog","Stormy","Windy","Sandstorms"])
city = st.selectbox("City", ["Urban","Semi-Urban","Metropolitan"])
order_time = st.selectbox("Order Time of Day", ["Morning","Afternoon","Evening","Night"])
# ---------------- ENCODING ----------------
traffic_map = {"Low":0,"Medium":1,"High":2,"Jam":3}
festival_map = {"No":0,"Yes":1}
weather_map = {"Sunny":1,"Cloudy":0,"Fog":0,"Stormy":0,"Windy":0,"Sandstorms":0}
city_map = {"Urban":1,"Semi-Urban":0,"Metropolitan":0}
order_time_map = {"Morning":1,"Afternoon":0,"Evening":0,"Night":0}
input_data = pd.DataFrame({
'age':[age],
'ratings':[ratings],
'vehicle_condition':[vehicle_condition],
'multiple_deliveries':[multiple_deliveries],
'distance':[distance],
'traffic':[traffic_map[traffic]],
'festival_yes':[festival_map[festival]],
'order_time_hour':[order_time_hour],
'order_time_of_day_morning':[order_time_map[order_time]],
'weather_sunny':[weather_map[weather]],
'city_type_urban':[city_map[city]]
})
# ---------------- PREDICTION ----------------
st.markdown("----")
if st.button("π Predict Delivery Time"):
with st.spinner("Calculating best route..."):
prediction = Model.predict(input_data)
delivery_time = round(prediction[0], 2)
st.markdown(f"""
<div class="prediction-box">
<h2 style="color:#fc8019;">Estimated Delivery Time</h2>
<h1>{delivery_time} Minutes β±οΈ</h1>
</div>
""", unsafe_allow_html=True)
st.progress(min(int(delivery_time), 100)) |