Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +19 -0
- app.py +61 -0
- app_streamlit.py +75 -0
- requirements.txt +11 -0
Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Use the official Python image
|
| 3 |
+
FROM python:3.9
|
| 4 |
+
|
| 5 |
+
# Set the working directory inside the container
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
# Copy the requirements file and install dependencies
|
| 9 |
+
COPY requirements.txt .
|
| 10 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 11 |
+
|
| 12 |
+
# Copy the rest of the app files
|
| 13 |
+
COPY . .
|
| 14 |
+
|
| 15 |
+
# Expose Streamlit's default port
|
| 16 |
+
EXPOSE 8501
|
| 17 |
+
|
| 18 |
+
# Run the Streamlit app
|
| 19 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
st.title("SuperKart Sales Forecaster")
|
| 6 |
+
st.write("Enter the details of the product and store to get a sales forecast.")
|
| 7 |
+
|
| 8 |
+
# Create input fields for the user
|
| 9 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, format="%f")
|
| 10 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
|
| 11 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, format="%f")
|
| 12 |
+
product_type = st.selectbox("Product Type", ['Dairy', 'Soft Drinks', 'Meat', 'Fruits and Vegetables', 'Household', 'Baking Goods', 'Snack Foods', 'Frozen Foods', 'Breakfast', 'Health and Hygiene', 'Hard Drinks', 'Canned', 'Bread', 'Starchy Foods', 'Others', 'Seafood'])
|
| 13 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0, format="%f")
|
| 14 |
+
store_id = st.selectbox("Store ID", [f"Store_{i}" for i in range(1, 11)])
|
| 15 |
+
store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2024, step=1)
|
| 16 |
+
store_size = st.selectbox("Store Size", ['Medium', 'High', 'Low'])
|
| 17 |
+
store_location_city_type = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 3', 'Tier 2'])
|
| 18 |
+
store_type = st.selectbox("Store Type", ['Supermarket Type 1', 'Supermarket Type 2', 'Departmental Store', 'Food Mart'])
|
| 19 |
+
|
| 20 |
+
# Prepare the data to be sent to the API
|
| 21 |
+
input_data = {
|
| 22 |
+
'Product_Weight': product_weight,
|
| 23 |
+
'Product_Sugar_Content': product_sugar_content,
|
| 24 |
+
'Product_Allocated_Area': product_allocated_area,
|
| 25 |
+
'Product_Type': product_type,
|
| 26 |
+
'Product_MRP': product_mrp,
|
| 27 |
+
'Store_Id': store_id,
|
| 28 |
+
'Store_Establishment_Year': store_establishment_year,
|
| 29 |
+
'Store_Size': store_size,
|
| 30 |
+
'Store_Location_City_Type': store_location_city_type,
|
| 31 |
+
'Store_Type': store_type,
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
if st.button("Predict Sales"):
|
| 35 |
+
# Send the data to the Flask API
|
| 36 |
+
try:
|
| 37 |
+
response = requests.post("https://pkulkar-SalesForcasterFrontend.hf.space/v1/sales", json=input_data)
|
| 38 |
+
if response.status_code == 200:
|
| 39 |
+
prediction = response.json()
|
| 40 |
+
st.success(f"Predicted Sales: {prediction['Predicted Price (in dollars)']:.2f}")
|
| 41 |
+
else:
|
| 42 |
+
st.error(f"Error predicting sales: {response.status_code} - {response.text}")
|
| 43 |
+
except requests.exceptions.RequestException as e:
|
| 44 |
+
st.error(f"Error connecting to the API: {e}")
|
| 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 Sales Batch"):
|
| 55 |
+
response = requests.post("https://pkulkar-SalesForcasterFrontend.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.")
|
app_streamlit.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Define the URL of your Flask API (replace with your Hugging Face Space URL)
|
| 6 |
+
API_URL = "https://pkulkar-salesforcastbackend.hf.space/v1/sales" # Replace with your Hugging Face Space URL
|
| 7 |
+
|
| 8 |
+
st.title("SuperKart Sales Forecaster")
|
| 9 |
+
st.write("Enter the details of the product and store to get a sales forecast.")
|
| 10 |
+
|
| 11 |
+
# Create input fields for the user
|
| 12 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, format="%f")
|
| 13 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
|
| 14 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, format="%f")
|
| 15 |
+
product_type = st.selectbox("Product Type", ['Dairy', 'Soft Drinks', 'Meat', 'Fruits and Vegetables', 'Household', 'Baking Goods', 'Snack Foods', 'Frozen Foods', 'Breakfast', 'Health and Hygiene', 'Hard Drinks', 'Canned', 'Bread', 'Starchy Foods', 'Others', 'Seafood'])
|
| 16 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0, format="%f")
|
| 17 |
+
store_id = st.selectbox("Store ID", [f"Store_{i}" for i in range(1, 11)])
|
| 18 |
+
store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2024, step=1)
|
| 19 |
+
store_size = st.selectbox("Store Size", ['Medium', 'High', 'Low'])
|
| 20 |
+
store_location_city_type = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 3', 'Tier 2'])
|
| 21 |
+
store_type = st.selectbox("Store Type", ['Supermarket Type 1', 'Supermarket Type 2', 'Departmental Store', 'Food Mart'])
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
if st.button("Predict Sales"):
|
| 25 |
+
# Prepare the data to be sent to the API
|
| 26 |
+
input_data = {
|
| 27 |
+
'Product_Weight': product_weight,
|
| 28 |
+
'Product_Sugar_Content': product_sugar_content,
|
| 29 |
+
'Product_Allocated_Area': product_allocated_area,
|
| 30 |
+
'Product_Type': product_type,
|
| 31 |
+
'Product_MRP': product_mrp,
|
| 32 |
+
'Store_Id': store_id,
|
| 33 |
+
'Store_Establishment_Year': store_establishment_year,
|
| 34 |
+
'Store_Size': store_size,
|
| 35 |
+
'Store_Location_City_Type': store_location_city_type,
|
| 36 |
+
'Store_Type': store_type,
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
# Send the data to the Flask API
|
| 40 |
+
try:
|
| 41 |
+
response = requests.post(API_URL, json=input_data)
|
| 42 |
+
|
| 43 |
+
if response.status_code == 200:
|
| 44 |
+
prediction = response.json()
|
| 45 |
+
st.success(f"Predicted Sales: {prediction['Predicted Price (in dollars)']:.2f}")
|
| 46 |
+
else:
|
| 47 |
+
st.error(f"Error predicting sales: {response.status_code} - {response.text}")
|
| 48 |
+
except requests.exceptions.RequestException as e:
|
| 49 |
+
st.error(f"Error connecting to the API: {e}")
|
| 50 |
+
|
| 51 |
+
# Create a requirements.txt file for the Streamlit app
|
| 52 |
+
%%writefile /content/drive/MyDrive/deployment_files/requirements_streamlit.txt
|
| 53 |
+
streamlit==1.43.2
|
| 54 |
+
requests==2.32.3
|
| 55 |
+
|
| 56 |
+
# Upload the Streamlit app file and requirements file to Hugging Face Space
|
| 57 |
+
from huggingface_hub import upload_file
|
| 58 |
+
|
| 59 |
+
repo_id_frontend = "pkulkar/SalesForcasterFrontend" # Replace with your Hugging Face Space ID for the frontend
|
| 60 |
+
|
| 61 |
+
upload_file(
|
| 62 |
+
path_or_fileobj="/content/drive/MyDrive/deployment_files/app_streamlit.py",
|
| 63 |
+
path_in_repo="app.py",
|
| 64 |
+
repo_id=repo_id_frontend,
|
| 65 |
+
repo_type="space",
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
upload_file(
|
| 69 |
+
path_or_fileobj="/content/drive/MyDrive/deployment_files/requirements_streamlit.txt",
|
| 70 |
+
path_in_repo="requirements.txt",
|
| 71 |
+
repo_id=repo_id_frontend,
|
| 72 |
+
repo_type="space",
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
```
|
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.32.3
|
| 10 |
+
uvicorn[standard]
|
| 11 |
+
streamlit==1.43.2
|