Upload folder using huggingface_hub
Browse files- app.py +60 -0
- requirements.txt +2 -3
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.title("SuperKart Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect business input for features
|
| 12 |
+
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
|
| 13 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
|
| 14 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, value=0.035)
|
| 15 |
+
Product_MRP = st.number_input("Product MRP", min_value=0.0, value=158.59)
|
| 16 |
+
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "Large"])
|
| 17 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 18 |
+
Store_Type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])
|
| 19 |
+
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1987, max_value=2009)
|
| 20 |
+
Product_Type = st.selectbox("Product Type", ["Baking Goods", "Frozen Foods", "Dairy", "Canned", "Health and Hygiene", "Snack Foods", "Meat", "Household", "Hard Drinks",
|
| 21 |
+
"Fruits and Vegetables", "Breads", "Soft Drinks", "Breakfast", "Others", "Starchy Foods", "Seafood"])
|
| 22 |
+
|
| 23 |
+
# Convert user input into a DataFrame
|
| 24 |
+
input_data = pd.DataFrame({
|
| 25 |
+
"Product_Weight": Product_Weight,
|
| 26 |
+
"Product_Sugar_Content": Product_Sugar_Content,
|
| 27 |
+
"Product_Allocated_Area": Product_Allocated_Area,
|
| 28 |
+
"Product_MRP": Product_MRP,
|
| 29 |
+
"Store_Size": Store_Size,
|
| 30 |
+
"Store_Location_City_Type": Store_Location_City_Type,
|
| 31 |
+
"Store_Type": Store_Type,
|
| 32 |
+
"Store_Establishment_Year": Store_Establishment_Year,
|
| 33 |
+
"Product_Type": Product_Type
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
# Make prediction when the "Predict" button is clicked
|
| 37 |
+
if st.button("Predict"):
|
| 38 |
+
response = requests.post("https://mbg0903-mbgspace.hf.space/v1/predict", json=input_data.to_dict(orient="records")[0])
|
| 39 |
+
if response.status_code == 200:
|
| 40 |
+
prediction = response.json()['Predicted Sales (in dollars)']
|
| 41 |
+
st.success(f"Predicted Sales (in dollars): {prediction}")
|
| 42 |
+
else:
|
| 43 |
+
st.error("Error making prediction.")
|
| 44 |
+
|
| 45 |
+
# Section for batch prediction
|
| 46 |
+
st.subheader("Batch Prediction")
|
| 47 |
+
|
| 48 |
+
# Allow users to upload a CSV file for batch prediction
|
| 49 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 50 |
+
|
| 51 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 52 |
+
if uploaded_file is not None:
|
| 53 |
+
if st.button("Predict Batch"):
|
| 54 |
+
response = requests.post("https://mbg0903-mbgspace.hf.space/v1/predict/batch", files={"file": uploaded_file})
|
| 55 |
+
if response.status_code == 200:
|
| 56 |
+
predictions = response.json()
|
| 57 |
+
st.success("Batch predictions completed!")
|
| 58 |
+
st.write(predictions) # Display the predictions
|
| 59 |
+
else:
|
| 60 |
+
st.error("Error making batch prediction.")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
pandas
|
| 3 |
-
streamlit
|
|
|
|
| 1 |
+
requests==2.32.3
|
| 2 |
+
pandas==2.2.2
|
|
|