Spaces:
No application file
No application file
Upload folder using huggingface_hub
Browse files- app.py +61 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.title("SuperKart Sales Forecast")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Sales Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for property features
|
| 12 |
+
product_weight = st.number_input(("Product Weight")
|
| 13 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
|
| 14 |
+
product_allocated_area = st.number_input(("Product Allocated Area")
|
| 15 |
+
product_type = st.selectbox("Product Type", ["Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household", "Baking Goods", "Canned",
|
| 16 |
+
"Health and Hygiene", "Meat", "Soft Drinks", "Breads", "Hard Drinks", "Others", "Starchy Foods", "Breakfast", "Seafood"])
|
| 17 |
+
product_mrp = st.number_input(("Product MRP")
|
| 18 |
+
store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, step=1)
|
| 19 |
+
store_size = st.number_input("Store Size", min_value=0, step=1, value=1)
|
| 20 |
+
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 21 |
+
store_type = st.selectbox("Store Type", ["Food Mart", "Departmental Store", "Supermarket Type1", "Supermarket Type2" ])
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Convert user input into a DataFrame
|
| 25 |
+
input_data = pd.DataFrame([{
|
| 26 |
+
'product_weight': product_weight,
|
| 27 |
+
'product_sugar_content': product_sugar_content,
|
| 28 |
+
'product_allocated_area': product_allocated_area,
|
| 29 |
+
'product_type': product_type,
|
| 30 |
+
'product_mrp': product_mrp,
|
| 31 |
+
'store_establishment_year': store_establishment_year
|
| 32 |
+
'store_size': store_size,
|
| 33 |
+
'store_location_city_type': store_location_city_type,
|
| 34 |
+
'store_type': store_type
|
| 35 |
+
}])
|
| 36 |
+
|
| 37 |
+
# Make prediction when the "Predict" button is clicked
|
| 38 |
+
if st.button("Predict"):
|
| 39 |
+
response = requests.post("https://aks2022-superkartsalesforecastbackend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
prediction = response.json()['Predicted Price (in dollars)']
|
| 42 |
+
st.success(f"Predicted Rental Price (in dollars): {prediction}")
|
| 43 |
+
else:
|
| 44 |
+
st.error("Error making prediction.")
|
| 45 |
+
|
| 46 |
+
# Section for batch prediction
|
| 47 |
+
st.subheader("Batch Prediction")
|
| 48 |
+
|
| 49 |
+
# Allow users to upload a CSV file for batch prediction
|
| 50 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 51 |
+
|
| 52 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 53 |
+
if uploaded_file is not None:
|
| 54 |
+
if st.button("Predict Batch"):
|
| 55 |
+
response = requests.post("https://aks2022-superkartsalesforecastbackend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
|
| 56 |
+
if response.status_code == 200:
|
| 57 |
+
predictions = response.json()
|
| 58 |
+
st.success("Batch predictions completed!")
|
| 59 |
+
st.write(predictions) # Display the predictions
|
| 60 |
+
else:
|
| 61 |
+
st.error("Error making batch prediction.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit
|
| 4 |
+
numpy
|
| 5 |
+
flask
|