Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +42 -0
- requirements.txt +3 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
-
|
| 11 |
-
COPY requirements.txt ./
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
|
|
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
-
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 8 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
RUN pip3 install -r requirements.txt
|
| 12 |
|
| 13 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
|
|
|
| 15 |
|
| 16 |
+
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Price Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for property features
|
| 12 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, max_value=100.0, step=1.0, value=90.0)
|
| 13 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
|
| 14 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, max_value=100.0, step=1.0, value=90.0)
|
| 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", min_value=0.0, max_value=100.0, step=1.0, value=90.0)
|
| 17 |
+
store_size = st.selectbox("Store Size", ['Medium', 'High', 'Small'])
|
| 18 |
+
store_location_city_type = st.selectbox("Store Location City Type", ['Tier 2', 'Tier 1', 'Tier 3'])
|
| 19 |
+
age_category = st.selectbox("Age_Category", ['0to20', '21to30', '31to50'])
|
| 20 |
+
type_of_food = st.selectbox("type of food", ['Perishable', 'Non-Consumables', 'Non-Perishable'])
|
| 21 |
+
|
| 22 |
+
# Convert user input into a DataFrame
|
| 23 |
+
input_data = pd.DataFrame([{
|
| 24 |
+
'product_weight': product_weight,
|
| 25 |
+
'product_sugar_content': product_sugar_content,
|
| 26 |
+
'product_allocated_area': product_allocated_area,
|
| 27 |
+
'product_type': product_type,
|
| 28 |
+
'product_mrp': product_mrp,
|
| 29 |
+
'store_size': store_size,
|
| 30 |
+
'store_location_city_type': store_location_city_type,
|
| 31 |
+
'age_category': age_category,
|
| 32 |
+
'type_of_food': type_of_food
|
| 33 |
+
}])
|
| 34 |
+
|
| 35 |
+
# Make prediction when the "Predict" button is clicked
|
| 36 |
+
if st.button("Predict"):
|
| 37 |
+
response = requests.post("https://RedRooster99-projectfrontend.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 38 |
+
if response.status_code == 200:
|
| 39 |
+
prediction = response.json()['Predicted Price']
|
| 40 |
+
st.success(f"Superkart Price: {prediction}")
|
| 41 |
+
else:
|
| 42 |
+
st.error("Error making prediction.")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|