adityasharma0511 commited on
Commit
384bf9c
·
verified ·
1 Parent(s): 4ee00b4

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+
5
+ # Set the title of the Streamlit app
6
+ st.title("Store Sales Prediction")
7
+
8
+ # Section for online prediction
9
+ st.subheader("Online Prediction")
10
+
11
+ # Collect user input for property features
12
+ Product_Sugar_Content = st.selectbox("Product_Sugar_Content" , ["Low Sugar", "Regular", "No Sugar"])
13
+ 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"
14
+ ])
15
+ Store_Id = st.selectbox("Store_Id" , ["OUT001","OUT002","OUT003","OUT004"])
16
+ Store_Size = st.selectbox("Store_Size" , ["Small","Medium","High"])
17
+ Store_Location_City_Type = st.selectbox("Store_Location_City_Type" , ["Tier 1","Tier 2","Tier 3"])
18
+ Store_Type = st.selectbox("Store_Type" , ["Supermarket Type1","Supermarket Type2","Departmental Store","Food Mart"])
19
+ Product_Weight = st.number_input("Product_Weight", min_value=0.00, max_value=100.00, step=0.01, value=0.0)
20
+ Product_Allocated_Area = st.number_input("Product_Allocated_Area", min_value=0.000, max_value=1.000, step=0.001, value=0.000)
21
+ Product_MRP = st.number_input("Product_Weight", min_value=0.0, step=0.01, value=0.0)
22
+ Store_Establishment_Year = st.number_input("Store_Establishment_Year", min_value=1800, max_value=3000, step=1, value=1900)
23
+
24
+
25
+ # Convert user input into a DataFrame
26
+ input_data = pd.DataFrame([{
27
+ 'Product_Weight':Product_Weight
28
+ 'Product_Sugar_Content':Product_Sugar_Content
29
+ 'Product_Allocated_Area':Product_Allocated_Area
30
+ 'Product_Type':Product_Type
31
+ 'Product_MRP':Product_MRP
32
+ 'Store_Id':Store_Id
33
+ 'Store_Establishment_Year':Store_Establishment_Year
34
+ 'Store_Size':Store_Size
35
+ 'Store_Location_City_Type':Store_Location_City_Type
36
+ 'Store_Type':Store_Type
37
+ }])
38
+
39
+ # Make prediction when the "Predict" button is clicked
40
+ if st.button("Predict"):
41
+ response = requests.post("https://adityasharma0511-StoreSalesPredictionBackend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
42
+ if response.status_code == 200:
43
+ prediction = response.json()['Predicted Price (in dollars)']
44
+ st.success(f"Predicted Store Sales (in dollars): {prediction}")
45
+ else:
46
+ st.error("Error making prediction.")
47
+
48
+ # Section for batch prediction
49
+ st.subheader("Batch Prediction")
50
+
51
+ # Allow users to upload a CSV file for batch prediction
52
+ uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
53
+
54
+ # Make batch prediction when the "Predict Batch" button is clicked
55
+ if uploaded_file is not None:
56
+ if st.button("Predict Batch"):
57
+ response = requests.post("https://adityasharma0511-StoreSalesPredictionBackend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
58
+ if response.status_code == 200:
59
+ predictions = response.json()
60
+ st.success("Batch predictions completed!")
61
+ st.write(predictions) # Display the predictions
62
+ else:
63
+ st.error("Error making batch prediction.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2