Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- app.py +67 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("Super Kart Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Product Weight
|
| 12 |
+
Product_Weight = st.number_input("Product Weight", min_value=1.0, max_value=100.0, value=10.0, step=0.1)
|
| 13 |
+
# Product Sugar Content
|
| 14 |
+
Product_Sugar_Content = st.selectbox("Product Sugar Content", options=["Low Sugar", "Regular", "No Sugar"])
|
| 15 |
+
# Product Allocated Area
|
| 16 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.01, max_value=1.00, value=0.05, step=0.01)
|
| 17 |
+
# Product Type
|
| 18 |
+
Product_Type = st.selectbox( "Product Type", options=["Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene"])
|
| 19 |
+
# Product MRP
|
| 20 |
+
Product_MRP = st.number_input("Product MRP", min_value=0.0, max_value=1000.0, value=100.0, step=1.0)
|
| 21 |
+
# Store Establishment Year
|
| 22 |
+
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2010, step=1)
|
| 23 |
+
# Store Size
|
| 24 |
+
Store_Size = st.selectbox("Store Size", options=["Small", "Medium", "High"])
|
| 25 |
+
# Store Location City Type
|
| 26 |
+
Store_Location_City_Type = st.selectbox("Store Location City Type", options=["Tier 1", "Tier 2", "Tier 3"])
|
| 27 |
+
# Store Type
|
| 28 |
+
Store_Type = st.selectbox("Store Type",options=["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])
|
| 29 |
+
|
| 30 |
+
# Convert user input into a DataFrame
|
| 31 |
+
input_data = pd.DataFrame([{
|
| 32 |
+
'Product_Weight': Product_Weight,
|
| 33 |
+
'Product_Sugar_Content': Product_Sugar_Content,
|
| 34 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 35 |
+
'Product_Type': Product_Type,
|
| 36 |
+
'Product_MRP': Product_MRP,
|
| 37 |
+
'Store_Establishment_Year': Store_Establishment_Year,
|
| 38 |
+
'Store_Size': Store_Size,
|
| 39 |
+
'Store_Location_City_Type': Store_Location_City_Type,
|
| 40 |
+
'Store_Type': Store_Type
|
| 41 |
+
}])
|
| 42 |
+
|
| 43 |
+
# Make prediction when the "Predict" button is clicked
|
| 44 |
+
if st.button("Predict"):
|
| 45 |
+
response = requests.post("https://cheeka84-SalesPredictionBackend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 46 |
+
if response.status_code == 200:
|
| 47 |
+
prediction = response.json()['Predicted Price (in dollars)']
|
| 48 |
+
st.success(f"Predicted Rental Price (in dollars): {prediction}")
|
| 49 |
+
else:
|
| 50 |
+
st.error("Error making prediction.")
|
| 51 |
+
|
| 52 |
+
# Section for batch prediction
|
| 53 |
+
st.subheader("Batch Prediction")
|
| 54 |
+
|
| 55 |
+
# Allow users to upload a CSV file for batch prediction
|
| 56 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 57 |
+
|
| 58 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 59 |
+
if uploaded_file is not None:
|
| 60 |
+
if st.button("Predict Batch"):
|
| 61 |
+
response = requests.post("https://cheeka84-SalesPredictionBackend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
|
| 62 |
+
if response.status_code == 200:
|
| 63 |
+
predictions = response.json()
|
| 64 |
+
st.success("Batch predictions completed!")
|
| 65 |
+
st.write(predictions) # Display the predictions
|
| 66 |
+
else:
|
| 67 |
+
st.error("Error making batch prediction.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|