VRS1503 commited on
Commit
4a1859d
·
verified ·
1 Parent(s): e6196a6

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +18 -0
  2. app.py +67 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ # Explicitly add Python's script directory to PATH
11
+ ENV PATH="/usr/local/bin:$PATH"
12
+
13
+ # Create the .streamlit directory if it doesn't exist and grant write permissions
14
+ RUN mkdir -p /.streamlit && chmod -R 777 /.streamlit
15
+
16
+ EXPOSE 8501
17
+
18
+ CMD ["streamlit", "run", "app.py"]
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("SuperKart Sales Predictor")
7
+
8
+ # Section for online prediction
9
+ st.subheader("Online Prediction")
10
+
11
+ # Collect business input for features
12
+ Product_Weight = st.number_input("Product Weight", min_value=0.0, max_value=100.0, step=0.1)
13
+ Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular"])
14
+ Product_Type = st.selectbox("Product Type", ["Perishable", "Non Perishable"])
15
+ Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.000, max_value=0.300, step=0.1)
16
+ Product_MRP = st.number_input("Product MRP", min_value=00.00, max_value=1000.00, step=0.1)
17
+ Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
18
+ Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
19
+ Store_Type = st.selectbox("Store Type", ["Departmental Store", "Food Mart", "Supermarket Type1", "Supermarket Type2"])
20
+ Store_Current_Age = st.number_input("Store Current Age", min_value=0, max_value=100, step=1)
21
+
22
+ # Convert user input into a DataFrame
23
+ business_df = pd.DataFrame({
24
+ 'Product_Weight': [Product_Weight],
25
+ 'Product_Sugar_Content': [Product_Sugar_Content],
26
+ 'Product_Type': [Product_Type],
27
+ 'Product_Allocated_Area': [Product_Allocated_Area],
28
+ 'Product_MRP': [Product_MRP],
29
+ 'Store_Size': [Store_Size],
30
+ 'Store_Location_City_Type': [Store_Location_City_Type],
31
+ 'Store_Type': [Store_Type],
32
+ 'Store_Current_Age': [Store_Current_Age] # Changed key name
33
+ })
34
+
35
+ # Make prediction when the "Predict" button is clicked
36
+ if st.button("Predict"):
37
+ backend_url = "https://vrs1503-superkart-backend.hf.space/v1/predict" # Ensure correct URL
38
+ try:
39
+ response = requests.post(backend_url, json=business_df.to_dict(orient="records")[0])
40
+ response.raise_for_status() # Raise an exception for bad status codes
41
+ data = response.json()
42
+ if 'prediction' in data:
43
+ prediction = data['prediction'][0] # Access the first element of the list
44
+ st.success(f"Predicted Sales (in dollars): {prediction}")
45
+ else:
46
+ st.error(f"Error: 'prediction' key not found in response. Response: {data}")
47
+ except requests.exceptions.RequestException as e:
48
+ st.error(f"Error making prediction: {e}")
49
+
50
+ # Section for batch prediction
51
+ st.subheader("Batch Prediction")
52
+
53
+ # Allow users to upload a CSV file for batch prediction
54
+ uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
55
+
56
+ # Make predictions when the "Predict" button is clicked
57
+ if uploaded_file is not None:
58
+ if st.button("Predict Batch"): # Changed button name to avoid duplication
59
+ backend_url = "https://vrs1503-superkart-backend.hf.space/v1/batch_predict" # Ensure correct URL
60
+ try:
61
+ response = requests.post(backend_url, files={"file": uploaded_file})
62
+ response.raise_for_status()
63
+ predictions = response.json()
64
+ st.success("Batch predictions completed!")
65
+ st.write(predictions) # Display the predictions
66
+ except requests.exceptions.RequestException as e:
67
+ st.error(f"Error making batch prediction: {e}")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Pandas==2.2.2
2
+ requests==2.32.3
3
+ streamlit==1.45.0
4
+ joblib==1.4.2
5
+ transformers
6
+ tensorflow[and-cuda]==2.18.0