Upload folder using huggingface_hub
Browse files- Dockerfile +9 -0
- app.py +74 -0
- requirements.txt +4 -0
Dockerfile
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.13
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY . .
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
+
|
| 9 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
def predict_sales(product_weight, product_sugar_content, product_allocated_area, product_type, product_mrp,
|
| 7 |
+
store_establishment_year, store_size, store_location_city_type, store_type):
|
| 8 |
+
# Create input dictionary
|
| 9 |
+
sample = {
|
| 10 |
+
'Product_Weight': product_weight,
|
| 11 |
+
'Product_Sugar_Content': product_sugar_content,
|
| 12 |
+
'Product_Allocated_Area': product_allocated_area,
|
| 13 |
+
'Product_Type': product_type,
|
| 14 |
+
'Product_MRP': product_mrp,
|
| 15 |
+
'Store_Establishment_Year': store_establishment_year,
|
| 16 |
+
'Store_Size': store_size,
|
| 17 |
+
'Store_Location_City_Type': store_location_city_type,
|
| 18 |
+
'Store_Type': store_type
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
# Convert to DataFrame
|
| 22 |
+
features_df = pd.DataFrame([sample])
|
| 23 |
+
|
| 24 |
+
# Apply one-hot encoding for nominal columns (matching backend)
|
| 25 |
+
features_df = pd.get_dummies(features_df, columns=['Product_Type', 'Store_Type'], drop_first=True)
|
| 26 |
+
|
| 27 |
+
# Apply ordinal encoding (based on backend mappings)
|
| 28 |
+
sugar_mapping = {'No Sugar': 0, 'Low Sugar': 1, 'Regular': 2}
|
| 29 |
+
size_mapping = {'Small': 0, 'Medium': 1, 'High': 2}
|
| 30 |
+
city_mapping = {'Tier 3': 0, 'Tier 2': 1, 'Tier 1': 2}
|
| 31 |
+
|
| 32 |
+
features_df['Product_Sugar_Content'] = features_df['Product_Sugar_Content'].map(sugar_mapping)
|
| 33 |
+
features_df['Store_Size'] = features_df['Store_Size'].map(size_mapping)
|
| 34 |
+
features_df['Store_Location_City_Type'] = features_df['Store_Location_City_Type'].map(city_mapping)
|
| 35 |
+
|
| 36 |
+
# Call the backend API
|
| 37 |
+
backend_url = "https://Hugo014-TotalSalesPredictionBackend.hf.space/v1/sales"
|
| 38 |
+
try:
|
| 39 |
+
response = requests.post(backend_url, json=sample)
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
result = response.json()
|
| 42 |
+
predicted_sales = result['Predicted Sales Total (in dollars)']
|
| 43 |
+
return f"The predicted sales total for the product is ${predicted_sales:.2f}."
|
| 44 |
+
else:
|
| 45 |
+
return f"Backend error: {response.status_code} - {response.text}"
|
| 46 |
+
except Exception as e:
|
| 47 |
+
return f"Error calling backend: {str(e)}"
|
| 48 |
+
|
| 49 |
+
# Gradio interface
|
| 50 |
+
demo = gr.Interface(
|
| 51 |
+
fn=predict_sales,
|
| 52 |
+
inputs=[
|
| 53 |
+
gr.Number(label="Product Weight", value=10.0, minimum=0.0, step=0.1),
|
| 54 |
+
gr.Dropdown(label="Product Sugar Content", choices=["No Sugar", "Low Sugar", "Regular"], value="Low Sugar"),
|
| 55 |
+
gr.Number(label="Product Allocated Area (sq ft)", value=500.0, minimum=0.0, step=1.0),
|
| 56 |
+
gr.Dropdown(label="Product Type", choices=[
|
| 57 |
+
"Dairy", "Soft Drinks", "Meat", "Fruits and Vegetables", "Snack Foods", "Household",
|
| 58 |
+
"Frozen Foods", "Baking Goods", "Canned", "Health and Hygiene", "Hard Drinks",
|
| 59 |
+
"Breads", "Starchy Foods", "Breakfast", "Seafood", "Others"
|
| 60 |
+
], value="Dairy"),
|
| 61 |
+
gr.Number(label="Product MRP (price)", value=100.0, minimum=0.0, step=1.0),
|
| 62 |
+
gr.Number(label="Store Establishment Year", value=2000, minimum=1900, maximum=2025, step=1),
|
| 63 |
+
gr.Dropdown(label="Store Size", choices=["Small", "Medium", "High"], value="Medium"),
|
| 64 |
+
gr.Dropdown(label="Store Location City Type", choices=["Tier 3", "Tier 2", "Tier 1"], value="Tier 1"),
|
| 65 |
+
gr.Dropdown(label="Store Type", choices=[
|
| 66 |
+
"Grocery Store", "Supermarket Type1", "Supermarket Type2", "Supermarket Type3"
|
| 67 |
+
], value="Supermarket Type1")
|
| 68 |
+
],
|
| 69 |
+
outputs=gr.Textbox(label="Prediction Result"),
|
| 70 |
+
title="Super Kart Product Sales Prediction App",
|
| 71 |
+
description="This tool predicts the total sales for a product based on store and product details."
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.48.1
|
| 4 |
+
gradio==5.42.0
|