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(""" """, unsafe_allow_html=True) # ---------------- LOAD MODEL ---------------- with open("model.pkl", "rb") as file: Model = pickle.load(file) # ---------------- TITLE ---------------- st.markdown('
🛵 Swiggy Delivery Time Prediction
', unsafe_allow_html=True) st.markdown('
Predict food delivery time instantly using Machine Learning
', 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"""

Estimated Delivery Time

{delivery_time} Minutes ⏱️

""", unsafe_allow_html=True) st.progress(min(int(delivery_time), 100))