Spaces:
Runtime error
Runtime error
Download app.py from danycontre/final-front: direct link, hf CLI and curl.
- Browser
- Download file 2.9 kB
-
https://huggingface.co/spaces/danycontre/final-front/resolve/main/app.py
- Command line
-
hf download hf://spaces/danycontre/final-front/app.py
-
curl -L -o app.py https://huggingface.co/spaces/danycontre/final-front/resolve/main/app.py
2.9 kB
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Streamlit UI for Customer Churn Prediction | |
| st.title("Product sales prediction") | |
| st.write("This tool predicts product sales on their details. Enter the required information below.") | |
| # Collect user input based on dataset columns | |
| Product_Id = st.text_input('Product ID'), | |
| Product_Weight = st.number_input('Product Weight'), | |
| Product_Sugar_Content = st.selectbox('Product Sugar Content', ['No Sugar', 'Low Sugar', 'Regular']), | |
| Product_Allocated_Area = st.number_input('Product Allocated Area'), | |
| 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', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood']), | |
| Product_MRP = st.number_input('Product MRP'), | |
| Store_Id = st.selectbox('Store ID', ['OUT004', 'OUT003', 'OUT001', 'OUT002']), | |
| Store_Size = st.selectbox('Store Size', ['Medium', 'High', 'Small']), | |
| Store_Establishment_Year = st.number_input('Store Establishment Year'), | |
| Store_Location_City_Type = st.selectbox('Store Location City Type', ['Tier 1', 'Tier 2', 'Tier 3']), | |
| Store_Type = st.selectbox('Store Type', ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1','Food Mart']) | |
| # Convert categorical inputs to match model training | |
| customer_data = { | |
| 'Product_Weight':Product_Weight, | |
| 'Product_Sugar_Content': Product_Sugar_Content, | |
| 'Product_Allocated_Area': Product_Allocated_Area, | |
| 'Product_Type': Product_Type, | |
| 'Product_MRP': Product_MRP, | |
| 'Store_Id': Store_Id, | |
| 'Store_Size': Store_Size, | |
| 'Store_Establishment_Year': Store_Establishment_Year, | |
| 'Store_Location_City_Type': Store_Location_City_Type, | |
| 'Store_Type': Store_Type | |
| } | |
| if st.button("Predict", type='primary'): | |
| response = requests.post("https://danycontre-final-backend.hf.space/v1/sales", json=customer_data) # enter user name and space name before running the cell | |
| if response.status_code == 200: | |
| result = response.json() | |
| sales_prediction = result["Prediction"] # Extract only the value | |
| st.write(f"Based on the information provided, the product with ID {Product_Id} will have sales off {sales_prediction}.") | |
| else: | |
| st.error("Error in API request") | |
| # Batch Prediction | |
| st.subheader("Batch Prediction") | |
| file = st.file_uploader("Upload CSV file", type=["csv"]) | |
| if file is not None: | |
| if st.button("Predict for Batch", type='primary'): | |
| response = requests.post("https://danycontre-final-backend.hf.space/v1/salesbatch", files={"file": file}) # enter user name and space name before running the cell | |
| if response.status_code == 200: | |
| result = response.json() | |
| st.header("Batch Prediction Results") | |
| st.write(result) | |
| else: | |
| st.error("Error in API request") | |