Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- app.py +66 -0
- requirements.txt +7 -3
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
model_root_url = "https://Fitjv-StoresalesPredictionBackend.hf.space"
|
| 6 |
+
model_predict_url = model_root_url+"/v1/sales" # Base URL of the deployed Flask API on Hugging Face Spaces
|
| 7 |
+
model_batch_url = model_root_url+"/v1/salesBatch"
|
| 8 |
+
|
| 9 |
+
# Set the title of the Streamlit app
|
| 10 |
+
st.title("SuperKart Store Sales Prediction")
|
| 11 |
+
|
| 12 |
+
# Section for online prediction
|
| 13 |
+
st.subheader("Online Prediction")
|
| 14 |
+
|
| 15 |
+
# Collect user input for property features
|
| 16 |
+
Product_Weight = st.number_input("Weight of the product", min_value=1.00, max_value=100.0, step=0.1, value=4.0)
|
| 17 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar","reg"])
|
| 18 |
+
Product_Allocated_Area = st.number_input("Display area Allocated", min_value=0.001, max_value=100.0, step=0.001, value=0.005)
|
| 19 |
+
Product_Type = st.selectbox("Product Type",["Frozen Foods","Dairy","Canned","Baking Goods","Health and Hygiene","Snack Foods","Meat","Household","Hard Drinks","Fruits and Vegetables","Breads",
|
| 20 |
+
"Soft Drinks","Breakfast","Others","Starchy Foods","Seafood"])
|
| 21 |
+
Product_MRP = st.number_input("Product Price", min_value=1, step=1, value=30)
|
| 22 |
+
Store_Id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003","OUT004"])
|
| 23 |
+
Store_Establishment_Year = st.number_input("Store Establishment year", min_value=1980, max_value=2009,step=1, value=1987)
|
| 24 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 25 |
+
Store_Location_City_Type = st.selectbox("Store Location City", ["Tier 1", "Tier 2", "Tier 3"])
|
| 26 |
+
Store_Type = st.selectbox("Store type", ["Food Mart", "Supermarket Type1", "Supermarket Type2"])
|
| 27 |
+
|
| 28 |
+
# Convert user input into a DataFrame
|
| 29 |
+
input_data = pd.DataFrame([{
|
| 30 |
+
'Weight of the product': Product_Weight,
|
| 31 |
+
'Product Sugar Content': Product_Sugar_Content,
|
| 32 |
+
'Display area Allocated': Product_Allocated_Area,
|
| 33 |
+
'Product Type': Product_Type,
|
| 34 |
+
'Store ID': Store_Id,
|
| 35 |
+
'Store Establishment year': Store_Establishment_Year,
|
| 36 |
+
'Product Price': Product_MRP,
|
| 37 |
+
'Store Size': Store_Size,
|
| 38 |
+
'Store Location City': Store_Location_City_Type,
|
| 39 |
+
'Store type': Store_Type
|
| 40 |
+
}])
|
| 41 |
+
|
| 42 |
+
# Make prediction when the "Predict" button is clicked
|
| 43 |
+
if st.button("Predict"):
|
| 44 |
+
response = requests.post("https://Fitjv-StoresalesPredictionBackend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 45 |
+
if response.status_code == 200:
|
| 46 |
+
prediction = response.json()['Predicted Sales (in dollars)']
|
| 47 |
+
st.success(f"Predicted Sales Price (in dollars): {prediction}")
|
| 48 |
+
else:
|
| 49 |
+
st.error("Error making prediction.")
|
| 50 |
+
|
| 51 |
+
# Section for batch prediction
|
| 52 |
+
st.subheader("Batch Prediction")
|
| 53 |
+
|
| 54 |
+
# Allow users to upload a CSV file for batch prediction
|
| 55 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 56 |
+
|
| 57 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 58 |
+
if uploaded_file is not None:
|
| 59 |
+
if st.button("Predict Batch"):
|
| 60 |
+
response = requests.post("https://<Fitjv>-<StoresalesPredictionBackend>.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
|
| 61 |
+
if response.status_code == 200:
|
| 62 |
+
predictions = response.json()
|
| 63 |
+
st.success("Batch predictions completed!")
|
| 64 |
+
st.write(predictions) # Display the predictions
|
| 65 |
+
else:
|
| 66 |
+
st.error("Error making batch prediction.")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
| 1 |
-
|
| 2 |
-
pandas
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests==2.28.1
|
| 2 |
+
pandas==2.2.2
|
| 3 |
+
numpy==2.0.2
|
| 4 |
+
scikit-learn==1.6.1
|
| 5 |
+
xgboost==2.1.4
|
| 6 |
+
joblib==1.4.2
|
| 7 |
+
streamlit==1.43.2
|