pkulkar commited on
Commit
ae938bd
·
verified ·
1 Parent(s): d655941

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +28 -38
app.py CHANGED
@@ -2,9 +2,6 @@ import streamlit as st
2
  import requests
3
  import json
4
 
5
- # Define the URL of your Flask API (replace with your Hugging Face Space URL)
6
- API_URL = "https://pkulkar-SalesForcasterFrontend.hf.space/v1/sales" # Replace with your Hugging Face Space URL
7
-
8
  st.title("SuperKart Sales Forecaster")
9
  st.write("Enter the details of the product and store to get a sales forecast.")
10
 
@@ -20,26 +17,24 @@ store_size = st.selectbox("Store Size", ['Medium', 'High', 'Low'])
20
  store_location_city_type = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 3', 'Tier 2'])
21
  store_type = st.selectbox("Store Type", ['Supermarket Type 1', 'Supermarket Type 2', 'Departmental Store', 'Food Mart'])
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  if st.button("Predict Sales"):
25
- # Prepare the data to be sent to the API
26
- input_data = {
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
  # Send the data to the Flask API
40
  try:
41
- response = requests.post(API_URL, json=input_data)
42
-
43
  if response.status_code == 200:
44
  prediction = response.json()
45
  st.success(f"Predicted Sales: {prediction['Predicted Price (in dollars)']:.2f}")
@@ -48,24 +43,19 @@ if st.button("Predict Sales"):
48
  except requests.exceptions.RequestException as e:
49
  st.error(f"Error connecting to the API: {e}")
50
 
 
 
51
 
52
- # Upload the Streamlit app file and requirements file to Hugging Face Space
53
- from huggingface_hub import upload_file
54
-
55
- repo_id_frontend = "pkulkar/SalesForcasterFrontend" # Replace with your Hugging Face Space ID for the frontend
56
 
57
- upload_file(
58
- path_or_fileobj="/content/drive/MyDrive/deployment_files/app_streamlit.py",
59
- path_in_repo="app.py",
60
- repo_id=repo_id_frontend,
61
- repo_type="space",
62
- )
63
-
64
- upload_file(
65
- path_or_fileobj="/content/drive/MyDrive/deployment_files/requirements_streamlit.txt",
66
- path_in_repo="requirements.txt",
67
- repo_id=repo_id_frontend,
68
- repo_type="space",
69
- )
70
-
71
- ```
 
2
  import requests
3
  import json
4
 
 
 
 
5
  st.title("SuperKart Sales Forecaster")
6
  st.write("Enter the details of the product and store to get a sales forecast.")
7
 
 
17
  store_location_city_type = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 3', 'Tier 2'])
18
  store_type = st.selectbox("Store Type", ['Supermarket Type 1', 'Supermarket Type 2', 'Departmental Store', 'Food Mart'])
19
 
20
+ # Prepare the data to be sent to the API
21
+ input_data = {
22
+ 'Product_Weight': product_weight,
23
+ 'Product_Sugar_Content': product_sugar_content,
24
+ 'Product_Allocated_Area': product_allocated_area,
25
+ 'Product_Type': product_type,
26
+ 'Product_MRP': product_mrp,
27
+ 'Store_Id': store_id,
28
+ 'Store_Establishment_Year': store_establishment_year,
29
+ 'Store_Size': store_size,
30
+ 'Store_Location_City_Type': store_location_city_type,
31
+ 'Store_Type': store_type,
32
+ }
33
 
34
  if st.button("Predict Sales"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  # Send the data to the Flask API
36
  try:
37
+ response = requests.post("https://pkulkar-SalesForcasterFrontend.hf.space/v1/sales", json=input_data)
 
38
  if response.status_code == 200:
39
  prediction = response.json()
40
  st.success(f"Predicted Sales: {prediction['Predicted Price (in dollars)']:.2f}")
 
43
  except requests.exceptions.RequestException as e:
44
  st.error(f"Error connecting to the API: {e}")
45
 
46
+ # Section for batch prediction
47
+ st.subheader("Batch Prediction")
48
 
49
+ # Allow users to upload a CSV file for batch prediction
50
+ uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
 
 
51
 
52
+ # Make batch prediction when the "Predict Batch" button is clicked
53
+ if uploaded_file is not None:
54
+ if st.button("Predict Sales Batch"):
55
+ response = requests.post("https://pkulkar-SalesForcasterFrontend.hf.space/v1/salesbatch", files={"file": uploaded_file}) # Send file to Flask API
56
+ if response.status_code == 200:
57
+ predictions = response.json()
58
+ st.success("Batch predictions completed!")
59
+ st.write(predictions) # Display the predictions
60
+ else:
61
+ st.error("Error making batch prediction.")