-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
KalyanMurapaka45
committed
Nov 13, 2023
1 parent
02c64e8
commit ec898bc
Showing
2 changed files
with
134 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
from flask import Flask, render_template, request | ||
from PIL import Image | ||
import pickle | ||
from flask import Flask, request, render_template | ||
from src.Airbnb.pipelines.Prediction_Pipeline import CustomData, PredictPipeline | ||
|
||
app = Flask(__name__) | ||
|
||
# Load the model | ||
model = pickle.load(open("catboostalgo.pkl", "rb")) | ||
|
||
# Define the home route | ||
@app.route("/", methods=["GET", "POST"]) | ||
def home(): | ||
if request.method == "POST": | ||
input_propertytype = int(request.form["propertytype"]) | ||
input_roomtype = int(request.form["roomtype"]) | ||
input_bedrooms = int(request.form["bedrooms"]) | ||
input_beds = int(request.form["beds"]) | ||
input_amenties = int(request.form["amenties"]) | ||
input_accommodates = int(request.form["accommodates"]) | ||
input_bathrooms = int(request.form["bathrooms"]) | ||
input_bedtype = int(request.form["bedtype"]) | ||
input_canceltype = int(request.form["canceltype"]) | ||
input_clean = int(request.form["clean"]) | ||
input_city = int(request.form["city"]) | ||
input_dp = int(request.form["dp"]) | ||
input_verify = int(request.form["verify"]) | ||
input_hostresponse = int(request.form["hostresponse"]) | ||
input_instbook = int(request.form["instbook"]) | ||
input_lat = float(request.form["lat"]) | ||
input_long = float(request.form["long"]) | ||
input_review = int(request.form["review"]) | ||
input_overallreview = int(request.form["overallreview"]) | ||
|
||
# Make a prediction | ||
prediction = model.predict([[input_propertytype, input_roomtype, input_amenties, input_accommodates, input_bathrooms, | ||
input_bedtype, input_canceltype, input_clean, input_city, input_dp, input_verify, | ||
input_hostresponse, input_instbook, input_lat, input_long, input_review, | ||
input_overallreview, input_bedrooms, input_beds]]) | ||
|
||
return str(prediction[0]) | ||
|
||
return render_template("index.html") | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True,host="0.0.0.0",port=5000) | ||
data = CustomData( | ||
property_type=request.form.get("propertytype"), | ||
room_type=request.form.get("roomtype"), | ||
bedrooms=int(request.form.get("bedrooms")), | ||
beds=int(request.form.get("beds")), | ||
amenities=int(request.form.get("amenties")), | ||
accommodates=int(request.form.get("accommodates")), | ||
bathrooms=float(request.form.get("bathrooms")), | ||
bed_type=request.form.get("bedtype"), | ||
cancellation_policy=request.form.get("canceltype"), | ||
cleaning_fee=float(request.form.get("clean")), | ||
city=request.form.get("city"), | ||
host_has_profile_pic=request.form.get("dp"), | ||
host_identity_verified=request.form.get("verify"), | ||
host_response_rate=request.form.get("hostresponse"), | ||
instant_bookable=request.form.get("instbook"), | ||
latitude=float(request.form.get("lat")), | ||
longitude=float(request.form.get("long")), | ||
number_of_reviews=int(request.form.get("review")), | ||
review_scores_rating=float(request.form.get("overallreview")) | ||
) | ||
|
||
final_data = data.get_data_as_dataframe() | ||
|
||
predict_pipeline = PredictPipeline() | ||
|
||
pred = predict_pipeline.predict(final_data) | ||
|
||
result = round(pred[0], 2) | ||
|
||
return render_template("result.html", final_result=result) | ||
|
||
# Execution begins | ||
if __name__ == '__main__': | ||
app.run(host="0.0.0.0", port=8080, debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import os | ||
import sys | ||
import pandas as pd | ||
from src.Airbnb.logger import logging | ||
from src.Airbnb.utils.utils import load_object | ||
from src.Airbnb.exception import customexception | ||
|
||
|
||
class PredictPipeline: | ||
def __init__(self): | ||
pass | ||
|
||
def predict(self, features): | ||
try: | ||
preprocessor_path = os.path.join("Artifacts", "Preprocessor.pkl") | ||
model_path = os.path.join("Artifacts", "Model.pkl") | ||
preprocessor = load_object(preprocessor_path) | ||
model = load_object(model_path) | ||
logging.info('Preprocessor and Model Pickle files loaded') | ||
scaled_data = preprocessor.transform(features) | ||
logging.info('Data Scaled') | ||
pred = model.predict(scaled_data) | ||
return pred | ||
except Exception as e: | ||
raise customexception(e, sys) | ||
|
||
class CustomData: | ||
def __init__(self, | ||
property_type: str, | ||
room_type: str, | ||
amenities: int, | ||
accommodates: int, | ||
bathrooms: float, | ||
bed_type: str, | ||
cancellation_policy: str, | ||
cleaning_fee: float, | ||
city: str, | ||
host_has_profile_pic: str, | ||
host_identity_verified: str, | ||
host_response_rate: str, | ||
instant_bookable: str, | ||
latitude: float, | ||
longitude: float, | ||
number_of_reviews: int, | ||
review_scores_rating: float, | ||
bedrooms: int, | ||
beds: int): | ||
|
||
self.property_type = property_type | ||
self.room_type = room_type | ||
self.amenities = amenities | ||
self.accommodates = accommodates | ||
self.bathrooms = bathrooms | ||
self.bed_type = bed_type | ||
self.cancellation_policy = cancellation_policy | ||
self.cleaning_fee = cleaning_fee | ||
self.city = city | ||
self.host_has_profile_pic = host_has_profile_pic | ||
self.host_identity_verified = host_identity_verified | ||
self.host_response_rate = host_response_rate | ||
self.instant_bookable = instant_bookable | ||
self.latitude = latitude | ||
self.longitude = longitude | ||
self.number_of_reviews = number_of_reviews | ||
self.review_scores_rating = review_scores_rating | ||
self.bedrooms = bedrooms | ||
self.beds = beds | ||
|
||
def get_data_as_dataframe(self): | ||
try: | ||
custom_data_input_dict = { | ||
'property_type': [self.property_type], | ||
'room_type': [self.room_type], | ||
'amenities': [self.amenities], | ||
'accommodates': [self.accommodates], | ||
'bathrooms': [self.bathrooms], | ||
'bed_type': [self.bed_type], | ||
'cancellation_policy': [self.cancellation_policy], | ||
'cleaning_fee': [self.cleaning_fee], | ||
'city': [self.city], | ||
'host_has_profile_pic': [self.host_has_profile_pic], | ||
'host_identity_verified': [self.host_identity_verified], | ||
'host_response_rate': [self.host_response_rate], | ||
'instant_bookable': [self.instant_bookable], | ||
'latitude': [self.latitude], | ||
'longitude': [self.longitude], | ||
'number_of_reviews': [self.number_of_reviews], | ||
'review_scores_rating': [self.review_scores_rating], | ||
'bedrooms': [self.bedrooms], | ||
'beds': [self.beds] | ||
} | ||
df = pd.DataFrame(custom_data_input_dict) | ||
logging.info('Dataframe Gathered') | ||
return df | ||
except Exception as e: | ||
logging.info('Exception Occurred in prediction pipeline') | ||
raise customexception(e, sys) |