Spaces:
Runtime error
Runtime error
Upload frontend app files
Browse files
https:/huggingface.co/spaces/Dattaluri/Great_Learning/blob/main/app.py/Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"]
|
| 15 |
+
|
| 16 |
+
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
https:/huggingface.co/spaces/Dattaluri/Great_Learning/blob/main/app.py/app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Define the backend API endpoint URL
|
| 7 |
+
# Replace with the actual URL of your deployed backend API
|
| 8 |
+
BACKEND_API_URL = "https://huggingface.co/spaces/Dattaluri/Great_Learning"
|
| 9 |
+
|
| 10 |
+
st.title("SuperKart Sales Forecast")
|
| 11 |
+
|
| 12 |
+
st.write("Enter the product and store details to get a sales forecast.")
|
| 13 |
+
|
| 14 |
+
# Create input fields for features
|
| 15 |
+
product_weight = st.number_input("Product Weight", min_value=0.0)
|
| 16 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
|
| 17 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0)
|
| 18 |
+
product_type = st.selectbox("Product Type", ["Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "Meat", "Snack Foods", "Hard Drinks", "Breakfast", "Household", "Breads", "Starchy Foods", "Fruits and Vegetables", "Seafood", "Others", "Soft Drinks"])
|
| 19 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0)
|
| 20 |
+
store_size = st.selectbox("Store Size", ["Medium", "High", "Small"])
|
| 21 |
+
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 2", "Tier 1", "Tier 3"])
|
| 22 |
+
store_type = st.selectbox("Store Type", ["Supermarket Type2", "Departmental Store", "Supermarket Type1", "Food Mart"])
|
| 23 |
+
store_establishment_year = st.number_input("Store Establishment Year", min_value=1985, max_value=2025, step=1)
|
| 24 |
+
|
| 25 |
+
# Create a button to trigger the prediction
|
| 26 |
+
if st.button("Get Sales Forecast"):
|
| 27 |
+
# Prepare the input data as a dictionary
|
| 28 |
+
input_data = {
|
| 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_Size": store_size,
|
| 35 |
+
"Store_Location_City_Type": store_location_city_type,
|
| 36 |
+
"Store_Type": store_type,
|
| 37 |
+
"Store_Establishment_Year": store_establishment_year # Include original year for 'Store_Age' calculation in backend
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Send the input data to the backend API for prediction
|
| 41 |
+
try:
|
| 42 |
+
response = requests.post(f"{https://huggingface.co/spaces/Dattaluri/Great_Learning/blob/main/app.py}/predict", json=input_data)
|
| 43 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
| 44 |
+
|
| 45 |
+
prediction = response.json()["prediction"][0]
|
| 46 |
+
st.success(f"The estimated sales total is: ${prediction:.2f}")
|
| 47 |
+
|
| 48 |
+
except requests.exceptions.RequestException as e:
|
| 49 |
+
st.error(f"Error communicating with the backend API: {e}")
|
| 50 |
+
except KeyError:
|
| 51 |
+
st.error("Invalid response from the backend API.")
|
https:/huggingface.co/spaces/Dattaluri/Great_Learning/blob/main/app.py/requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.36.0
|
| 2 |
+
requests==2.32.3
|
| 3 |
+
pandas==2.2.2
|