Polarisailabs commited on
Commit
dc1e79c
·
verified ·
1 Parent(s): 4dfb6c6

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -67
app.py CHANGED
@@ -1,67 +1,23 @@
1
- import gradio as gr
2
- import numpy as np
3
- import pandas as pd
4
- from nltk.corpus import stopwords
5
- from nltk.tokenize import word_tokenize
6
- from nltk.stem.wordnet import WordNetLemmatizer
7
- import nltk
8
-
9
- nltk.download('punkt_tab')
10
- nltk.download('stopwords')
11
- nltk.download('wordnet')
12
- #nltk.download('omw-1.4')
13
- #nltk.download('averaged_perceptron_tagger')
14
-
15
-
16
- # Import the dataset
17
- df = pd.read_csv('Hotel_Reviews.csv')
18
- df['countries'] = df.Hotel_Address.apply(lambda x: x.split(' ')[-1])
19
-
20
- # Define the function to recommend hotels
21
- def Input_your_destination_and_description(location,description):
22
- # Making these columns lowercase
23
- df['countries']=df['countries'].str.lower()
24
- df['Tags']=df['Tags'].str.lower()
25
-
26
- # Dividing the texts into small tokens (sentences into words)
27
- description = description.lower()
28
- description_tokens=word_tokenize(description)
29
-
30
- sw = stopwords.words('english') # List of predefined english stopwords to be used for computing
31
- lemm = WordNetLemmatizer() # We now define the functions below connecting these imported packages
32
- filtered_sen = {w for w in description_tokens if not w in sw}
33
- f_set=set()
34
- for fs in filtered_sen:
35
- f_set.add(lemm.lemmatize(fs))
36
-
37
- # Defining a new variable that takes in the location inputted and bring out the features defined below
38
- country_feat = df[df['countries']==location.lower()]
39
- country_feat = country_feat.set_index(np.arange(country_feat.shape[0]))
40
- cos=[];
41
- for i in range(country_feat.shape[0]):
42
- temp_tokens=word_tokenize(country_feat['Tags'][i])
43
- temp1_set={w for w in temp_tokens if not w in sw}
44
- temp_set=set()
45
- for se in temp1_set:
46
- temp_set.add(lemm.lemmatize(se))
47
- rvector = temp_set.intersection(f_set)
48
- cos.append(len(rvector))
49
- country_feat['similarity']=cos
50
- country_feat=country_feat.sort_values(by='similarity',ascending=False)
51
- country_feat.drop_duplicates(subset='Hotel_Name',keep='first',inplace=True)
52
- country_feat.sort_values('Average_Score',ascending=False,inplace=True)
53
- country_feat.reset_index(inplace=True)
54
- return country_feat[['Hotel_Name','Average_Score','Hotel_Address']].head(10)
55
-
56
- # Create the input interface
57
- inputs = [gr.Textbox(label="Location"),
58
- gr.Textbox(label="Purpose of Travel")]
59
-
60
- # Create the output interface
61
- outputs=gr.Dataframe(label="Hotel Recommendations",type="pandas")
62
-
63
- # Create the interface
64
- gr.Interface(fn=Input_your_destination_and_description,
65
- inputs=inputs,
66
- outputs=outputs,theme=gr.themes.Default(primary_hue="sky")).launch()
67
-
 
1
+ _A='countries'
2
+ import gradio as gr,numpy as np,pandas as pd
3
+ from nltk.corpus import stopwords
4
+ from nltk.tokenize import word_tokenize
5
+ from nltk.stem.wordnet import WordNetLemmatizer
6
+ import nltk
7
+ nltk.download('punkt_tab')
8
+ nltk.download('stopwords')
9
+ nltk.download('wordnet')
10
+ df=pd.read_csv('Hotel_Reviews.csv')
11
+ df[_A]=df.Hotel_Address.apply(lambda x:x.split(' ')[-1])
12
+ def Input_your_destination_and_description(location,description):
13
+ 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()
14
+ for P in O:G.add(F.lemmatize(P))
15
+ A=df[df[_A]==location.lower()];A=A.set_index(np.arange(A.shape[0]));H=[]
16
+ for Q in range(A.shape[0]):
17
+ R=word_tokenize(A[C][Q]);S={A for A in R if not A in E};I=set()
18
+ for T in S:I.add(F.lemmatize(T))
19
+ U=I.intersection(G);H.append(len(U))
20
+ 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)
21
+ inputs=[gr.Textbox(label='Location'),gr.Textbox(label='Purpose of Travel')]
22
+ outputs=gr.Dataframe(label='Hotel Recommendations',type='pandas')
23
+ gr.Interface(fn=Input_your_destination_and_description,inputs=inputs,outputs=outputs,theme=gr.themes.Default(primary_hue='sky')).launch()