amit14official commited on
Commit
f3ba4d1
·
verified ·
1 Parent(s): 6384b82

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. app.py +60 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+
6
+ COPY requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ COPY app.py .
10
+
11
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import streamlit as st
3
+ import pandas as pd
4
+
5
+
6
+ # Set the title of the Streamlit app
7
+ st.title("Airbnb Rental Price Prediction")
8
+
9
+ # Section for online prediction
10
+ st.subheader("Online Prediction")
11
+
12
+ # Collect user input for property features
13
+ room_type = st.selectbox("Room Type", ["Entire home/apt", "Private room", "Shared room"])
14
+ accommodates = st.number_input("Accommodates (Number of guests)", min_value=1, value=2)
15
+ bathrooms = st.number_input("Bathrooms", min_value=1, step=1, value=2)
16
+ cancellation_policy = st.selectbox("Cancellation Policy (kind of cancellation policy)", ["strict", "flexible", "moderate"])
17
+ cleaning_fee = st.selectbox("Cleaning Fee Charged?", ["True", "False"])
18
+ instant_bookable = st.selectbox("Instantly Bookable?", ["False", "True"])
19
+ review_scores_rating = st.number_input("Review Score Rating", min_value=0.0, max_value=100.0, step=1.0, value=90.0)
20
+ bedrooms = st.number_input("Bedrooms", min_value=0, step=1, value=1)
21
+ beds = st.number_input("Beds", min_value=0, step=1, value=1)
22
+
23
+ # Convert user input into a DataFrame
24
+ input_data = pd.DataFrame([{
25
+ 'room_type': room_type,
26
+ 'accommodates': accommodates,
27
+ 'bathrooms': bathrooms,
28
+ 'cancellation_policy': cancellation_policy,
29
+ 'cleaning_fee': cleaning_fee,
30
+ 'instant_bookable': 'f' if instant_bookable=="False" else "t", # Convert to 't' or 'f'
31
+ 'review_scores_rating': review_scores_rating,
32
+ 'bedrooms': bedrooms,
33
+ 'beds': beds
34
+ }])
35
+
36
+ # Make prediction when the "Predict" button is clicked
37
+ if st.button("Predict"):
38
+ response = requests.post("https://amit14official-RentalPricePredictionBackend.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
39
+ if response.status_code == 200:
40
+ prediction = response.json()['Predicted Price (in dollars)']
41
+ st.success(f"Predicted Rental Price (in dollars): {prediction}")
42
+ else:
43
+ st.error("Error making prediction.")
44
+
45
+ # Section for batch prediction
46
+ st.subheader("Batch Prediction")
47
+
48
+ # Allow users to upload a CSV file for batch prediction
49
+ uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
50
+
51
+ # Make batch prediction when the "Predict Batch" button is clicked
52
+ if uploaded_file is not None:
53
+ if st.button("Predict Batch"):
54
+ response = requests.post("https://amit14official-RentalPricePredictionBackend.hf.space/v1/rentalbatch", files={"file": uploaded_file}) # Send file to Flask API
55
+ if response.status_code == 200:
56
+ predictions = response.json()
57
+ st.success("Batch predictions completed!")
58
+ st.write(predictions) # Display the predictions
59
+ else:
60
+ st.error("Error making batch prediction.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2