Upload folder using huggingface_hub
Browse files- Dockerfile +8 -13
- app.py +69 -0
- requirements.txt +3 -3
Dockerfile
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
software-properties-common \
|
| 9 |
-
git \
|
| 10 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
-
|
| 12 |
-
COPY requirements.txt ./
|
| 13 |
-
COPY src/ ./src/
|
| 14 |
|
|
|
|
| 15 |
RUN pip3 install -r requirements.txt
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 20 |
|
| 21 |
-
|
|
|
|
| 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,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("Extraa Learn conversion Predictor")
|
| 7 |
+
|
| 8 |
+
# Section for conversion prediction
|
| 9 |
+
st.subheader("conversion Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for property features
|
| 12 |
+
|
| 13 |
+
age = st.number_input("age", min_value=1, value=65)
|
| 14 |
+
website_visits = st.number_input("website_visits", min_value=0, value=30)
|
| 15 |
+
time_spent_on_website = st.number_input("time_spent_on_website", min_value=0, value=2000)
|
| 16 |
+
page_views_per_visit = st.number_input("page_views_per_visit", min_value=0, value=20)
|
| 17 |
+
current_occupation = st.selectbox("current occupation", ["professional", "unemployed", "student"])
|
| 18 |
+
first_interaction = st.selectbox("first interaction", ["Website", "Mobile App"])
|
| 19 |
+
profile_completed = st.selectbox("profile completed", ["High", "medium", "Low"])
|
| 20 |
+
last_activity = st.selectbox("last activity", ["Email Activity", "Phone Activity", "Website Activity"])
|
| 21 |
+
print_media_type1 = st.selectbox("media type1", ["yes", "NO"])
|
| 22 |
+
print_media_type2 = st.selectbox("media type2", ["yes", "NO"]),
|
| 23 |
+
digital_media = st.selectbox("digital media", ["yes", "NO"]),
|
| 24 |
+
educational_channels = st.selectbox("educational channels", ["yes", "NO"])
|
| 25 |
+
referral = st.selectbox("referral", ["yes", "NO"])
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Convert user input into a DataFrame
|
| 29 |
+
input_data = pd.DataFrame([{
|
| 30 |
+
'age': age,
|
| 31 |
+
'website_visits': website_visits,
|
| 32 |
+
'time_spent_on_website': time_spent_on_website,
|
| 33 |
+
'page_views_per_visit': page_views_per_visit,
|
| 34 |
+
'current_occupation': current_occupation,
|
| 35 |
+
'first_interaction': first_interaction,
|
| 36 |
+
'profile_completed': profile_completed,
|
| 37 |
+
'last_activity': last_activity,
|
| 38 |
+
'print_media_type1': print_media_type1,
|
| 39 |
+
'print_media_type2': print_media_type2,
|
| 40 |
+
'digital_media': digital_media,
|
| 41 |
+
'educational_channels': educational_channels,
|
| 42 |
+
'referral': referral
|
| 43 |
+
}])
|
| 44 |
+
|
| 45 |
+
# Make prediction when the "Predict" button is clicked
|
| 46 |
+
if st.button("Predict"):
|
| 47 |
+
response = requests.post("https://amitcoolll-ExtraLearnConversionPredictionBackendAPP.hf.space/v1/conversion", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 48 |
+
if response.status_code == 200:
|
| 49 |
+
prediction = response.json()['Predicted Price (in dollars)']
|
| 50 |
+
st.success(f"Predicted Rental Price (in dollars): {prediction}")
|
| 51 |
+
else:
|
| 52 |
+
st.error("Error making prediction.")
|
| 53 |
+
|
| 54 |
+
# Section for batch prediction
|
| 55 |
+
st.subheader("Batch Prediction")
|
| 56 |
+
|
| 57 |
+
# Allow users to upload a CSV file for batch prediction
|
| 58 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 59 |
+
|
| 60 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 61 |
+
if uploaded_file is not None:
|
| 62 |
+
if st.button("Predict Batch"):
|
| 63 |
+
response = requests.post("https://amitcoolll-ExtraLearnConversionPredictionBackendAPP.hf.space/v1/conversionbatch", files={"file": uploaded_file}) # Send file to Flask API
|
| 64 |
+
if response.status_code == 200:
|
| 65 |
+
predictions = response.json()
|
| 66 |
+
st.success("Batch predictions completed!")
|
| 67 |
+
st.write(predictions) # Display the predictions
|
| 68 |
+
else:
|
| 69 |
+
st.error("Error making batch 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
|