Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +16 -0
- app.py +61 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
+
RUN pip3 install -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
| 15 |
+
|
| 16 |
+
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# Set the title of the Streamlit app
|
| 7 |
+
st.title("SuperKart Sales Prediction")
|
| 8 |
+
|
| 9 |
+
# Section for online prediction
|
| 10 |
+
st.subheader("Predict Single Product Sales")
|
| 11 |
+
|
| 12 |
+
# Collect user input for product and store features
|
| 13 |
+
product_id = st.text_input("Product ID", value="FD6114")
|
| 14 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66, step=0.1)
|
| 15 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
|
| 16 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.027, step=0.001)
|
| 17 |
+
product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Household', 'Meat', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood', 'Fruits and Vegetables', 'Snack Foods'])
|
| 18 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0, value=117.08, step=0.01)
|
| 19 |
+
store_id = st.selectbox("Store ID", ["OUT004", "OUT003", "OUT001", "OUT002"])
|
| 20 |
+
store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2009, step=1)
|
| 21 |
+
store_size = st.selectbox("Store Size", ["Medium", "High", "Small"])
|
| 22 |
+
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 2", "Tier 1", "Tier 3"])
|
| 23 |
+
store_type = st.selectbox("Store Type", ["Supermarket Type2", "Departmental Store", "Supermarket Type1", "Food Mart"])
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Convert user input into a dictionary
|
| 27 |
+
input_data = {
|
| 28 |
+
"Product_Id": product_id,
|
| 29 |
+
"Product_Weight": product_weight,
|
| 30 |
+
"Product_Sugar_Content": product_sugar_content,
|
| 31 |
+
"Product_Allocated_Area": product_allocated_area,
|
| 32 |
+
"Product_Type": product_type,
|
| 33 |
+
"Product_MRP": product_mrp,
|
| 34 |
+
"Store_Id": store_id,
|
| 35 |
+
"Store_Establishment_Year": store_establishment_year,
|
| 36 |
+
"Store_Size": store_size,
|
| 37 |
+
"Store_Location_City_Type": store_location_city_type,
|
| 38 |
+
"Store_Type": store_type
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
# Make prediction when the "Predict" button is clicked
|
| 42 |
+
if st.button("Predict"):
|
| 43 |
+
# Replace with your actual Hugging Face Space backend URL
|
| 44 |
+
backend_url = "https://retheesh-superkartsalesprediction.hf.space/predict_sales" # Replace with your space URL and endpoint
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
response = requests.post(backend_url, json=input_data)
|
| 48 |
+
|
| 49 |
+
if response.status_code == 200:
|
| 50 |
+
prediction = response.json().get('predicted_sales')
|
| 51 |
+
if prediction is not None:
|
| 52 |
+
st.success(f"Predicted Product Store Sales Total: {prediction:.2f}")
|
| 53 |
+
else:
|
| 54 |
+
st.error("Prediction not found in the response.")
|
| 55 |
+
st.json(response.json()) # Display the full response for debugging
|
| 56 |
+
else:
|
| 57 |
+
st.error(f"Error predicting sales. Status code: {response.status_code}")
|
| 58 |
+
st.write("Response body:", response.text) # Display response text for debugging
|
| 59 |
+
st.json(response.json()) # Display response json for debugging
|
| 60 |
+
except requests.exceptions.RequestException as e:
|
| 61 |
+
st.error(f"Error connecting to the backend API: {e}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.3.1
|
| 2 |
+
requests==2.32.3
|
| 3 |
+
streamlit==1.43.2
|