Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +66 -0
- requirements.txt +2 -2
Dockerfile
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
-
|
| 11 |
-
COPY requirements.txt ./
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
|
|
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
-
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9-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,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
st.title(" SuperKart Sales Prediction App")
|
| 6 |
+
|
| 7 |
+
st.write("Predict the **Product_Store_Sales_Total** using Machine Learning!")
|
| 8 |
+
|
| 9 |
+
# ------------------------------
|
| 10 |
+
# Single Input Prediction (Online)
|
| 11 |
+
# ------------------------------
|
| 12 |
+
st.header(" Single Prediction")
|
| 13 |
+
|
| 14 |
+
# Input fields
|
| 15 |
+
Product_Weight = st.number_input("Product Weight", min_value=0.0, step=0.1)
|
| 16 |
+
Product_Allocated_Area = st.number_input("Allocated Area", min_value=0.0, step=1.0)
|
| 17 |
+
Product_MRP = st.number_input("Product MRP", min_value=0.0, step=1.0)
|
| 18 |
+
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2010)
|
| 19 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 20 |
+
Store_Location_City_Type = st.selectbox("City Type", ["Tier 3", "Tier 2", "Tier 1"])
|
| 21 |
+
Product_Sugar_Content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
|
| 22 |
+
Product_Type = st.text_input("Product Type (e.g., Snack Foods)")
|
| 23 |
+
Store_Type = st.text_input("Store Type (e.g., Supermarket Type 1)")
|
| 24 |
+
|
| 25 |
+
data = {
|
| 26 |
+
"Product_Weight": Product_Weight,
|
| 27 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 28 |
+
"Product_MRP": Product_MRP,
|
| 29 |
+
"Store_Establishment_Year": Store_Establishment_Year,
|
| 30 |
+
"Store_Size": Store_Size,
|
| 31 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 32 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 33 |
+
"Product_Type": Product_Type,
|
| 34 |
+
"Store_Type": Store_Type,
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if st.button("Predict Sales"):
|
| 38 |
+
try:
|
| 39 |
+
response = requests.post("https://Rajanan-Backend.hf.space/v1/predict", json=data)
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
result = response.json()
|
| 42 |
+
st.success(f" Predicted Sales: {result['Predicted_Product_Store_Sales_Total']}")
|
| 43 |
+
else:
|
| 44 |
+
st.error(" Error from API!")
|
| 45 |
+
except:
|
| 46 |
+
st.error(" Unable to connect to backend API")
|
| 47 |
+
|
| 48 |
+
# ------------------------------
|
| 49 |
+
# Batch Prediction (Upload CSV)
|
| 50 |
+
# ------------------------------
|
| 51 |
+
st.header(" Batch Prediction (Upload CSV)")
|
| 52 |
+
|
| 53 |
+
uploaded_file = st.file_uploader("Upload CSV File", type=['csv'])
|
| 54 |
+
|
| 55 |
+
if uploaded_file:
|
| 56 |
+
if st.button("Predict Batch Sales"):
|
| 57 |
+
try:
|
| 58 |
+
response = requests.post("https://Rajanan-Backend.hf.space/v1/predict_batch", files={"file": uploaded_file})
|
| 59 |
+
if response.status_code == 200:
|
| 60 |
+
result = pd.read_json(response.text)
|
| 61 |
+
st.write(result)
|
| 62 |
+
st.success(" Batch predictions generated!")
|
| 63 |
+
else:
|
| 64 |
+
st.error("Error from backend API")
|
| 65 |
+
except:
|
| 66 |
+
st.error("Failed to connect to API")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
|
| 2 |
pandas
|
| 3 |
-
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
pandas
|
| 3 |
+
requests
|