harasar commited on
Commit
b4c318a
·
verified ·
1 Parent(s): 6b110dd

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +73 -0
  2. requirements.txt +3 -3
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import numpy as np
5
+ import requests
6
+
7
+
8
+ # Streamlit UI for Price Prediction
9
+ st.title("SuperKart Sales Predictor")
10
+ st.write("This tool predicts the sales based on various store parameters.")
11
+
12
+ st.subheader("Enter the store details(Single Predication):")
13
+
14
+ # Collect user input
15
+ product_weight = st.number_input("Product Weight (in kg)", min_value=1.0, max_value=30.0)
16
+ product_sugar = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
17
+ product_area = st.slider("Allocated Area (sq m)", min_value=0.0, max_value=1.0, step=0.01)
18
+ product_type = st.selectbox("Product Type", ["Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household","Baking Goods", "Canned", "Health and Hygiene", "Meat", "Breads","Hard Drinks", "Soft Drinks", "Seafood", "Starchy Foods", "Others"])
19
+ product_mrp = st.number_input("Product MRP", min_value=10.0, max_value=300.0)
20
+ store_year = st.number_input("Store Establishment Year", min_value=1980, max_value=2025)
21
+ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
22
+ store_city = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
23
+ store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", "Departmental Store"])
24
+
25
+ # Prepare input
26
+ if st.button("Predict Sales"):
27
+ input_df = {
28
+ "Product_Weight": product_weight,
29
+ "Product_Sugar_Content": product_sugar,
30
+ "Product_Allocated_Area": product_area,
31
+ "Product_Type": product_type,
32
+ "Product_MRP": product_mrp,
33
+ "Store_Establishment_Year": 2025 - store_year, # we have modified this to get the store age
34
+ "Store_Size": store_size,
35
+ "Store_Location_City_Type": store_city,
36
+ "Store_Type": store_type
37
+ }
38
+ response = requests.post("https://harasar-SuperKartBackend.hf.space/v1/customer", json=input_df) # enter user name and space name before running the cell
39
+ if response.status_code == 200:
40
+ result = response.json()
41
+ churn_prediction = result["predicted_sales"] # Extract only the value
42
+ st.write(f"Based on the information provided, the sproject sales is likely to {churn_prediction}.")
43
+ else:
44
+ st.error("Error in API request")
45
+
46
+ #Batch Prediction
47
+ uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
48
+
49
+ if st.button("Predict for Batch"):
50
+ if uploaded_file is not None:
51
+ try:
52
+ # Convert uploaded file to a DataFrame
53
+ df = pd.read_csv(uploaded_file)
54
+
55
+ # Convert DataFrame to CSV bytes like your working script
56
+ csv_bytes = df.to_csv(index=False).encode('utf-8')
57
+
58
+ # Send POST request with raw bytes
59
+ response = requests.post(
60
+ "https://harasar-SuperKartBackend.hf.space/v1/customerbatch",
61
+ files={"file": ("SuperKart.csv", csv_bytes, "text/csv")}
62
+ )
63
+
64
+ if response.status_code == 200:
65
+ st.success("Batch prediction successful!")
66
+ st.write(response.json())
67
+ else:
68
+ st.error(f"Error {response.status_code}: {response.text}")
69
+
70
+ except Exception as e:
71
+ st.error(f"Upload failed: {e}")
72
+ else:
73
+ st.warning("Please upload a CSV file first.")
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2