Muleex12 commited on
Commit
acadbb0
·
verified ·
1 Parent(s): 8bfd452

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -38
app.py CHANGED
@@ -1,39 +1,62 @@
 
 
1
 
2
- import streamlit as st
3
- import requests
4
-
5
- st.title("_____") #Complete the code to define the title of the app.
6
-
7
- # Input fields for product and store data
8
- Product_Weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
9
- Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
10
- Product_Allocated_Area = ______ #Complete the code to define the UI element for Product_Allocated_Area
11
- Product_MRP = ______ #Complete the code to define the UI element for Product_MRP
12
- Store_Size = _____ ______ #Complete the code to define the UI element for Store_Size
13
- Store_Location_City_Type = _____ ______ #Complete the code to define the UI element for Store_Location_City_Type
14
- Store_Type = _____ ______ #Complete the code to define the UI element for Store_Type
15
- Product_Id_char = _____ ______ #Complete the code to define the UI element for Product_Id_char
16
- Store_Age_Years = _____ ______ #Complete the code to define the UI element for Store_Age_Years
17
- Product_Type_Category = _____ ______ #Complete the code to define the UI element for Product_Type_Category
18
-
19
- product_data = {
20
- "Product_Weight": Product_Weight,
21
- "Product_Sugar_Content": Product_Sugar_Content,
22
- "Product_Allocated_Area": Product_Allocated_Area,
23
- "Product_MRP": Product_MRP,
24
- "Store_Size": Store_Size,
25
- "Store_Location_City_Type": Store_Location_City_Type,
26
- "Store_Type": Store_Type,
27
- "Product_Id_char": Product_Id_char,
28
- "Store_Age_Years": Store_Age_Years,
29
- "Product_Type_Category": Product_Type_Category
30
- }
31
-
32
- if st.button("Predict", type='primary'):
33
- response = requests.post("https://<user_name>-<space_name>.hf.space/v1/predict", json=product_data) # Complete the code to enter user name and space name to correctly define the endpoint
34
- if response.status_code == 200:
35
- result = response.json()
36
- predicted_sales = result["Sales"]
37
- st.write(f"Predicted Product Store Sales Total: ₹{predicted_sales:.2f}")
38
- else:
39
- st.error("Error in API request")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
 
4
+ # Load model
5
+ model = joblib.load("model.pkl")
6
+
7
+ # Prediction function
8
+ def predict(
9
+ Product_Weight,
10
+ Product_Sugar_Content,
11
+ Product_Allocated_Area,
12
+ Product_Type,
13
+ Product_MRP,
14
+ Store_Establishment_Year,
15
+ Store_Size,
16
+ Store_Location_City_Type,
17
+ Store_Type,
18
+ Product_Type_Category,
19
+ Product_Id_char
20
+ ):
21
+
22
+ input_data = [[
23
+ Product_Weight,
24
+ Product_Sugar_Content,
25
+ Product_Allocated_Area,
26
+ Product_Type,
27
+ Product_MRP,
28
+ Store_Establishment_Year,
29
+ Store_Size,
30
+ Store_Location_City_Type,
31
+ Store_Type,
32
+ Product_Type_Category,
33
+ Product_Id_char
34
+ ]]
35
+
36
+ prediction = model.predict(input_data)
37
+
38
+ return round(float(prediction[0]), 2)
39
+
40
+
41
+ # UI DESIGN
42
+ interface = gr.Interface(
43
+ fn=predict,
44
+ inputs=[
45
+ gr.Number(label="Product Weight"),
46
+ gr.Dropdown(["Low Sugar", "Regular"], label="Sugar Content"),
47
+ gr.Number(label="Allocated Area"),
48
+ gr.Dropdown(["Food", "Drinks", "Meat", "Household"], label="Product Type"),
49
+ gr.Number(label="Product Price (MRP)"),
50
+ gr.Number(label="Store Establishment Year"),
51
+ gr.Dropdown(["Small", "Medium", "High"], label="Store Size"),
52
+ gr.Dropdown(["Tier 1", "Tier 2", "Tier 3"], label="City Type"),
53
+ gr.Dropdown(["Grocery Store", "Supermarket Type1", "Supermarket Type2", "Supermarket Type3"], label="Store Type"),
54
+ gr.Dropdown(["Food", "Non-Consumable", "Drinks"], label="Product Category"),
55
+ gr.Dropdown(["FD", "DR", "NC"], label="Product ID Type")
56
+ ],
57
+ outputs=gr.Number(label="Predicted Sales"),
58
+ title="🛒 SuperKart Sales Prediction",
59
+ description="Enter product and store details to predict sales"
60
+ )
61
+
62
+ interface.launch()