productizationlabs's picture
Upload app.py
f3228bd
_A='countries'
import gradio as gr,numpy as np,pandas as pd
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.stem.wordnet import WordNetLemmatizer
import nltk
nltk.download('punkt')
nltk.download('stopwords')
nltk.download('wordnet')
df=pd.read_csv('Hotel_Reviews.csv')
df[_A]=df.Hotel_Address.apply(lambda x:x.split(' ')[-1])
def Input_your_destination_and_description(location,description):
M='Average_Score';L='Hotel_Name';K=False;J='similarity';D=True;C='Tags';B=description;df[_A]=df[_A].str.lower();df[C]=df[C].str.lower();B=B.lower();N=word_tokenize(B);E=stopwords.words('english');F=WordNetLemmatizer();O={A for A in N if not A in E};G=set()
for P in O:G.add(F.lemmatize(P))
A=df[df[_A]==location.lower()];A=A.set_index(np.arange(A.shape[0]));H=[]
for Q in range(A.shape[0]):
R=word_tokenize(A[C][Q]);S={A for A in R if not A in E};I=set()
for T in S:I.add(F.lemmatize(T))
U=I.intersection(G);H.append(len(U))
A[J]=H;A=A.sort_values(by=J,ascending=K);A.drop_duplicates(subset=L,keep='first',inplace=D);A.sort_values(M,ascending=K,inplace=D);A.reset_index(inplace=D);return A[[L,M,'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,theme=gr.themes.Default(primary_hue='slate')).launch()