Download app.py from Anil28053/Frontend: direct link, hf CLI and curl.
- Browser
- Download file 2.94 kB
-
https://huggingface.co/spaces/Anil28053/Frontend/resolve/main/app.py
- Command line
-
hf download hf://spaces/Anil28053/Frontend/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Anil28053/Frontend/resolve/main/app.py
2.94 kB
| import requests | |
| import streamlit as st | |
| import pandas as pd | |
| st.title("Sales Forecaster") | |
| # Batch Prediction | |
| st.subheader("Predicting Sales") | |
| # Input fields for product data | |
| Product_Id = st.text_input("Product ID", value="FD6114") | |
| Product_Weight = st.number_input("Product Weight", min_value=0.0, max_value=22.0, format="%.2f") | |
| Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"]) | |
| Product_Allocated_Area = st.number_input("Product Allocated Area (Ratio of Total Area) ", min_value=0.0, max_value=1.0, format="%.2f") | |
| Product_Type = st.selectbox("Type Of Product", ["Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household", "Baking Goods", "Canned", "Health and Hygiene", "Meat", "Soft Drinks", "Breads", "Hard Drinks","Others", "Starchy Foods", "Breakfast", "Seafood"]) | |
| Product_MRP = st.number_input("Price of Product", min_value=0.0, format="%.2f") | |
| Store_Id = st.selectbox("Store ID", ["OUT004", "OUT001", "OUT003", "OUT002"]) | |
| Store_Establishment_Year = st.number_input("Year of Store Establishment", min_value=1800, max_value=2025, value=2008) | |
| Store_Size = st.selectbox("Size of Store", ["High", "Medium", "Small"]) | |
| Store_Location_City_Type = st.selectbox("City Tier of the Store", ["Tier 1", "Tier 2", "Tier 3"]) | |
| Store_Type = st.selectbox("Type of Store", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"]) | |
| product_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_Establishment_Year': Store_Establishment_Year, | |
| 'Store_Size': Store_Size, | |
| 'Store_Location_City_Type': Store_Location_City_Type, | |
| 'Store_Type': Store_Type | |
| } | |
| if st.button("Predict", type='primary'): | |
| response = requests.post("https://Anil28053-Backend.hf.space/v1/customer", json=product_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.success(f"Based on the provided info, Product {Product_Id} is forecasted to generate sales of ₹{sales_prediction:.2f}") | |
| 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://Anil28053-Backend.hf.space/v1/customerbatch", 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") | |