Upload folder using huggingface_hub
Browse files- Dockerfile +8 -13
- app.py +47 -0
- rental_price_prediction_model_v1_0.joblib +3 -0
- requirements.txt +6 -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,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import joblib
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
@st.cache_resource
|
| 9 |
+
def load_model():
|
| 10 |
+
return joblib.load("rental_price_prediction_model_v1_0.joblib")
|
| 11 |
+
|
| 12 |
+
model = load_model()
|
| 13 |
+
|
| 14 |
+
# Streamlit UI for Price Prediction
|
| 15 |
+
st.title("Airbnb Rental Price Prediction App")
|
| 16 |
+
st.write("This tool predicts the price of an Airbnb listing based on the property details.")
|
| 17 |
+
|
| 18 |
+
st.subheader("Enter the listing details:")
|
| 19 |
+
|
| 20 |
+
# Collect user input
|
| 21 |
+
room_type = st.selectbox("Room Type", ["Entire home/apt", "Private room", "Shared room"])
|
| 22 |
+
accommodates = st.number_input("Accommodates (Number of guests)", min_value=1, value=2)
|
| 23 |
+
bathrooms = st.number_input("Bathrooms", min_value=1, step=1, value=2)
|
| 24 |
+
cancellation_policy = st.selectbox("Cancellation Policy (kind of cancellation policy)", ["strict", "flexible", "moderate"])
|
| 25 |
+
cleaning_fee = st.selectbox("Cleaning Fee Charged?", ["True", "False"])
|
| 26 |
+
instant_bookable = st.selectbox("Instantly Bookable?", ["False", "True"])
|
| 27 |
+
review_scores_rating = st.number_input("Review Score Rating", min_value=0.0, max_value=100.0, step=1.0, value=90.0)
|
| 28 |
+
bedrooms = st.number_input("Bedrooms", min_value=0, step=1, value=1)
|
| 29 |
+
beds = st.number_input("Beds", min_value=0, step=1, value=1)
|
| 30 |
+
|
| 31 |
+
# Convert user input into a DataFrame
|
| 32 |
+
input_data = pd.DataFrame([{
|
| 33 |
+
'room_type': room_type,
|
| 34 |
+
'accommodates': accommodates,
|
| 35 |
+
'bathrooms': bathrooms,
|
| 36 |
+
'cancellation_policy': cancellation_policy,
|
| 37 |
+
'cleaning_fee': cleaning_fee,
|
| 38 |
+
'instant_bookable': 'f' if instant_bookable=="False" else "t",
|
| 39 |
+
'review_scores_rating': review_scores_rating,
|
| 40 |
+
'bedrooms': bedrooms,
|
| 41 |
+
'beds': beds
|
| 42 |
+
}])
|
| 43 |
+
|
| 44 |
+
# Predict button
|
| 45 |
+
if st.button("Predict"):
|
| 46 |
+
prediction = model.predict(input_data)
|
| 47 |
+
st.write(f"The predicted price of the rental property is ${np.exp(prediction)[0]:.2f}.")
|
rental_price_prediction_model_v1_0.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a373f720cb8147ba06379bff712827966fbd4e5b14074c35f79f6290a44b88f3
|
| 3 |
+
size 90868
|
requirements.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.7.1
|
| 4 |
+
xgboost==3.0.2
|
| 5 |
+
joblib==1.5.1
|
| 6 |
+
streamlit==1.43.2
|