Download app.py from Meenakshi9182/SwiggyDeliveryTimePredictionUsingML: direct link, hf CLI and curl.
- Browser
- Download file 3.6 kB
-
https://huggingface.co/spaces/Meenakshi9182/SwiggyDeliveryTimePredictionUsingML/resolve/main/app.py
- Command line
-
hf download hf://spaces/Meenakshi9182/SwiggyDeliveryTimePredictionUsingML/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Meenakshi9182/SwiggyDeliveryTimePredictionUsingML/resolve/main/app.py
3.6 kB
| 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)) |