|
import gradio as gr |
|
import numpy as np |
|
import pandas as pd |
|
from nltk.corpus import stopwords |
|
from nltk.tokenize import word_tokenize |
|
from nltk.stem.wordnet import WordNetLemmatizer |
|
|
|
|
|
df = pd.read_csv('Hotel_Reviews.csv') |
|
df['countries'] = df.Hotel_Address.apply(lambda x: x.split(' ')[-1]) |
|
|
|
|
|
def Input_your_destination_and_description(location,description): |
|
|
|
df['countries']=df['countries'].str.lower() |
|
df['Tags']=df['Tags'].str.lower() |
|
|
|
|
|
description = description.lower() |
|
description_tokens=word_tokenize(description) |
|
|
|
sw = stopwords.words('english') |
|
lemm = WordNetLemmatizer() |
|
filtered_sen = {w for w in description_tokens if not w in sw} |
|
f_set=set() |
|
for fs in filtered_sen: |
|
f_set.add(lemm.lemmatize(fs)) |
|
|
|
|
|
country_feat = df[df['countries']==location.lower()] |
|
country_feat = country_feat.set_index(np.arange(country_feat.shape[0])) |
|
cos=[]; |
|
for i in range(country_feat.shape[0]): |
|
temp_tokens=word_tokenize(country_feat['Tags'][i]) |
|
temp1_set={w for w in temp_tokens if not w in sw} |
|
temp_set=set() |
|
for se in temp1_set: |
|
temp_set.add(lemm.lemmatize(se)) |
|
rvector = temp_set.intersection(f_set) |
|
cos.append(len(rvector)) |
|
country_feat['similarity']=cos |
|
country_feat=country_feat.sort_values(by='similarity',ascending=False) |
|
country_feat.drop_duplicates(subset='Hotel_Name',keep='first',inplace=True) |
|
country_feat.sort_values('Average_Score',ascending=False,inplace=True) |
|
country_feat.reset_index(inplace=True) |
|
return country_feat[['Hotel_Name','Average_Score','Hotel_Address']].head(10) |
|
|
|
|
|
inputs = [gr.inputs.Textbox(label="Location"), |
|
gr.inputs.Textbox(label="Purpose of Travel")] |
|
|
|
|
|
outputs=gr.outputs.Dataframe(label="Hotel Recommendations",type="pandas") |
|
|
|
|
|
gr.Interface(fn=Input_your_destination_and_description, |
|
inputs=inputs, |
|
outputs=outputs).launch() |
|
|
|
|