Spaces:
Sleeping
Sleeping
# app.py | |
import streamlit as st | |
import joblib | |
import pandas as pd | |
from sklearn.linear_model import LinearRegression | |
pipe = joblib.load('lr_regression_ny2019.pkl') | |
st.title('Airbnb price predictor') | |
st.markdown(""" | |
**Example data:** | |
- "latitude": 40.7128 | |
- "longitude": -74.006 | |
- "minimum_nights": 3.0 | |
- "number_of_reviews": 5.0 | |
- "reviews_per_month": 1.0 | |
- "calculated_host_listings_count": 1.0 | |
- "availability_365": 365.0 | |
- "neighbourhood_group": "Manhattan" | |
- "neighbourhood": "Financial District" | |
- "room_type": "Entire home/apt" | |
The result should be 268 dollar! | |
Tutorial how to build this kind of app: [Link](https://medium.com/latinxinai/how-i-deployed-a-machine-learning-model-for-the-first-time-b82b9ea831e0) | |
""") | |
def get_user_input(): | |
input_dict = { | |
"latitude": 40.7128, | |
"longitude": -74.006, | |
"minimum_nights": 3.0, | |
"number_of_reviews": 5.0, | |
"reviews_per_month": 1.0, | |
"calculated_host_listings_count": 1.0, | |
"availability_365": 365.0, | |
"neighbourhood_group": "Manhattan", | |
"neighbourhood": "Financial District", | |
"room_type": "Entire home/apt" | |
} | |
input_features = [ | |
"latitude", "longitude", "minimum_nights", "number_of_reviews", | |
"reviews_per_month", "calculated_host_listings_count", | |
"availability_365", "neighbourhood_group", "neighbourhood", "room_type" | |
] | |
with st.form(key='my_form'): | |
for feat in input_features: | |
if feat in ['neighbourhood_group','neighbourhood','room_type']: | |
input_value = st.text_input(f"Enter value for {feat}", value=input_dict[feat]) | |
else: | |
input_value = st.number_input(f"Enter value for {feat}", value=input_dict[feat], step=1.0) | |
input_dict[feat] = input_value | |
submit_button = st.form_submit_button(label='Submit') | |
return pd.DataFrame([input_dict]), submit_button | |
user_input, submit_button = get_user_input() | |
if submit_button: | |
# Predict wine quality | |
prediction = pipe.predict(user_input) | |
prediction_value = prediction[0] | |
# Display the prediction | |
st.header("Predicted Airbnb price") | |
st.write(f"the prediction is {prediction_value:.2f} dollar!") |