Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +18 -0
- app.py +89 -0
- requirements.txt +11 -0
Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python base image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy all files into the container
|
| 8 |
+
COPY . /app
|
| 9 |
+
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN pip install --upgrade pip && \
|
| 12 |
+
pip install -r requirements.txt
|
| 13 |
+
|
| 14 |
+
# Expose port for Streamlit
|
| 15 |
+
EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
# Run Streamlit app
|
| 18 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
app.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# import
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
# Streamlit UI
|
| 8 |
+
st.title("SuperKart Sales Prediction App")
|
| 9 |
+
st.write("Predict store sales based on product and store attributes.")
|
| 10 |
+
|
| 11 |
+
# Numerical Input fields
|
| 12 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, step=0.1)
|
| 13 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, step=0.1)
|
| 14 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0, step=0.1)
|
| 15 |
+
store_age = st.number_input("Store Age (in years)", min_value=0, step=1)
|
| 16 |
+
|
| 17 |
+
# Categorical inputs with options adapted from your data
|
| 18 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
|
| 19 |
+
product_type = st.selectbox(
|
| 20 |
+
"Product Type",['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene',
|
| 21 |
+
'Snack Foods', 'Meat', 'Household', 'Hard Drinks', 'Fruits and Vegetables',
|
| 22 |
+
'Breads', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood'])
|
| 23 |
+
store_type = st.selectbox("Store Type",['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
|
| 24 |
+
store_size = st.selectbox("Store Size (1=Small, 2=Medium, 3=Large)",[1, 2, 3])
|
| 25 |
+
store_location_city_type = st.selectbox("Store Location City Type (1=Tier 1, 2=Tier 2, 3=Tier 3)",[1, 2, 3])
|
| 26 |
+
|
| 27 |
+
input_data = pd.DataFrame([{
|
| 28 |
+
'Product_Weight': product_weight,
|
| 29 |
+
'Product_Sugar_Content': product_sugar_content,
|
| 30 |
+
'Product_Allocated_Area': product_allocated_area,
|
| 31 |
+
'Product_Type': product_type,
|
| 32 |
+
'Product_MRP': product_mrp,
|
| 33 |
+
'Store_Size': store_size,
|
| 34 |
+
'Store_Location_City_Type': store_location_city_type,
|
| 35 |
+
'Store_Type': store_type,
|
| 36 |
+
'Store_Age': store_age
|
| 37 |
+
}])
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# Predict button
|
| 41 |
+
if st.button("Predict"):
|
| 42 |
+
try:
|
| 43 |
+
response = requests.post(
|
| 44 |
+
"https://Vaddiritz-SuperKartBackend.hf.space/v1/salesprice",
|
| 45 |
+
json=input_data.to_dict(orient='records')[0]
|
| 46 |
+
)
|
| 47 |
+
if response.status_code == 200:
|
| 48 |
+
prediction = response.json().get("Predicted Price", "No prediction returned")
|
| 49 |
+
st.success(f"Predicted Sales Price: {prediction}")
|
| 50 |
+
else:
|
| 51 |
+
st.error("Error making prediction.")
|
| 52 |
+
st.text(response.text)
|
| 53 |
+
except Exception as e:
|
| 54 |
+
st.error(f"Exception occurred: {e}")
|
| 55 |
+
|
| 56 |
+
# ----------------- Batch Prediction -----------------
|
| 57 |
+
st.subheader("Batch Prediction")
|
| 58 |
+
|
| 59 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 60 |
+
|
| 61 |
+
if uploaded_file is not None:
|
| 62 |
+
if st.button("PredictBatch"):
|
| 63 |
+
try:
|
| 64 |
+
files = {"file": (uploaded_file.name, uploaded_file, "text/csv")}
|
| 65 |
+
response = requests.post(
|
| 66 |
+
"https://Vaddiritz-SuperKartBackend.hf.space/v1/salespricebatch",
|
| 67 |
+
files=files
|
| 68 |
+
)
|
| 69 |
+
if response.status_code == 200:
|
| 70 |
+
predictions = response.json()
|
| 71 |
+
st.success("Batch predictions completed!")
|
| 72 |
+
|
| 73 |
+
# Convert to DataFrame and display
|
| 74 |
+
df_predictions = pd.DataFrame(predictions)
|
| 75 |
+
st.dataframe(df_predictions)
|
| 76 |
+
|
| 77 |
+
# Download button
|
| 78 |
+
csv = df_predictions.to_csv(index=False).encode('utf-8')
|
| 79 |
+
st.download_button(
|
| 80 |
+
label="Download Predictions as CSV",
|
| 81 |
+
data=csv,
|
| 82 |
+
file_name="SuperKart_Predicted_Sales.csv",
|
| 83 |
+
mime="text/csv"
|
| 84 |
+
)
|
| 85 |
+
else:
|
| 86 |
+
st.error("Error making batch prediction.")
|
| 87 |
+
st.text(response.text)
|
| 88 |
+
except Exception as e:
|
| 89 |
+
st.error(f"Exception occurred: {e}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
xgboost==2.1.4
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
Werkzeug==2.2.2
|
| 7 |
+
flask==2.2.2
|
| 8 |
+
gunicorn==20.1.0
|
| 9 |
+
requests==2.28.1
|
| 10 |
+
streamlit==1.43.2
|
| 11 |
+
flask-cors==3.0.10
|