bhumitps commited on
Commit
7a85880
·
verified ·
1 Parent(s): bc3592f

Upload ./app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+ import json
5
+
6
+ st.title("SuperKart Sales Forecasting")
7
+
8
+ st.write("Enter the details of the product and store to get a sales forecast.")
9
+
10
+ # Input fields for the user to provide data
11
+ product_id = st.text_input("Product ID")
12
+ product_weight = st.number_input("Product Weight", value=10.0, format="%.2f")
13
+ product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar', 'reg'])
14
+ product_allocated_area = st.number_input("Product Allocated Area", value=0.1, format="%.3f")
15
+ 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'])
16
+ product_mrp = st.number_input("Product MRP", value=150.0, format="%.2f")
17
+ store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002'])
18
+ store_establishment_year = st.number_input("Store Establishment Year", value=2000, format="%d")
19
+ store_size = st.selectbox("Store Size", ['Medium', 'High', 'Small'])
20
+ store_location_city_type = st.selectbox("Store Location City Type", ['Tier 2', 'Tier 1', 'Tier 3'])
21
+ store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
22
+
23
+ # Create a dictionary with the input data
24
+ input_data = {
25
+ 'Product_Id': product_id,
26
+ 'Product_Weight': product_weight,
27
+ 'Product_Sugar_Content': product_sugar_content,
28
+ 'Product_Allocated_Area': product_allocated_area,
29
+ 'Product_Type': product_type,
30
+ 'Product_MRP': product_mrp,
31
+ 'Store_Id': store_id,
32
+ 'Store_Establishment_Year': store_establishment_year,
33
+ 'Store_Size': store_size,
34
+ 'Store_Location_City_Type': store_location_city_type,
35
+ 'Store_Type': store_type
36
+ }
37
+
38
+ # Button to trigger prediction
39
+ if st.button("Predict Sales"):
40
+ # Hugging Face proxy URL for Flask backend
41
+ backend_url = "https://huggingface.co/spaces/bhumitps/md-be/predict"
42
+
43
+ try:
44
+ # Send a POST request to the backend API
45
+ response = requests.post(backend_url, json=[input_data]) # Send as a list of one data point
46
+
47
+ # Check if the request was successful
48
+ if response.status_code == 200:
49
+ predictions = response.json().get('predictions')
50
+ if predictions:
51
+ st.success(f"Predicted Sales: {predictions[0]:.2f}")
52
+ else:
53
+ st.error("Error: Could not retrieve predictions from the backend.")
54
+ else:
55
+ st.error(f"Error: Received status code {response.status_code} from the backend.")
56
+ st.error(f"Response: {response.text}")
57
+
58
+ except requests.exceptions.RequestException as e:
59
+ st.error(f"Error connecting to the backend API: {e}")