alvi15tooba commited on
Commit
fdd8012
1 Parent(s): 3dae4e2

Upload folder using huggingface_hub

Browse files
Assignment_04_Miami_Hotel_Search.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
LLM_v2_module_5_large_embedding.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Hackathon Gradio App
3
- emoji: 🌖
4
- colorFrom: red
5
- colorTo: blue
6
  sdk: gradio
7
  sdk_version: 4.21.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: hackathon-gradio-app
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 4.21.0
 
 
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title =("<center>"
2
+ "<p>""Welcome to Hotel Recommendation System!""</p>"
3
+ "</center>")
4
+
5
+ head = (
6
+ "<center>"
7
+ "<img src='https://img.freepik.com/free-vector/hotel-tower-concept-illustration_114360-12962.jpg?w=740&t=st=1710571774~exp=1710572374~hmac=6daf26dbfb918ba737df6d2f091351ab0348437afeff121f973efd2d55bfe092' width=400>"
8
+ "The robot was trained to search for relevant hotels from the dataset provided."
9
+ "</center>"
10
+ )
11
+
12
+ #importing libraries
13
+ import requests
14
+ import os
15
+ import gradio as gr
16
+ import pandas as pd
17
+ import pprint
18
+ from sentence_transformers import SentenceTransformer, CrossEncoder, util
19
+ from openai.embeddings_utils import get_embedding, cosine_similarity
20
+ df = pd.read_pickle('data.pkl')
21
+ embedder = SentenceTransformer('all-mpnet-base-v2')
22
+ def search(query,pprint=True):
23
+ n = 15
24
+ query_embedding = embedder.encode(query,show_progress_bar=True) #encode the query
25
+ df["rev_sim_score"] = df.embed_1.apply(lambda x: cosine_similarity(x, query_embedding.reshape(768,-1))) #similarity against each doc
26
+ review_results = (
27
+ df.sort_values("rev_sim_score", ascending=False) # re-rank
28
+ .head(n))
29
+ resultlist = []
30
+ hlist = []
31
+ for r in review_results.index:
32
+ if review_results.hotel_name[r] not in hlist:
33
+ smalldf = review_results.loc[review_results.hotel_name == review_results.hotel_name[r]]
34
+ smallarr = smalldf.rev_sim_score[r].max()
35
+ sm =smalldf.rate[r].mean()
36
+ if smalldf.shape[1] > 3:
37
+ smalldf = smalldf[:3]
38
+ resultlist.append(
39
+ {
40
+ "hotel_name":review_results.hotel_name[r],
41
+ "description":review_results.hotel_description[r],
42
+ "relevance score": smallarr.tolist(),
43
+ "rating": sm.tolist(),
44
+ "relevant_reviews": [ smalldf.hotel_info[s] for s in smalldf.index]
45
+ })
46
+ hlist.append(review_results.hotel_name[r])
47
+ return resultlist
48
+
49
+ def hotel_info(query, pprint=True):
50
+ query_embedding = embedder.encode(query,show_progress_bar=True) #encode the query
51
+ df["hotel_sim_score"] = df.embed_2.apply(lambda x: cosine_similarity(x, query_embedding.reshape(768,-1)))
52
+ #similarity against each doc
53
+ n=3
54
+ hotel_results = (
55
+ df.sort_values("hotel_sim_score", ascending=False) # re-rank
56
+ .head(n))
57
+ resultlist = []
58
+ hlist = []
59
+ for r in hotel_results.index:
60
+ if hotel_results.hotel_name[r] not in hlist:
61
+ smalldf = hotel_results.loc[hotel_results.hotel_name == hotel_results.hotel_name[r]]
62
+ smallarr = smalldf.hotel_sim_score[r].max()
63
+ sm =smalldf.rate[r].mean()
64
+ if smalldf.shape[1] > 3:
65
+ smalldf = smalldf[:3]
66
+ resultlist.append(
67
+ {
68
+ "name":hotel_results.hotel_name[r],
69
+ "description":hotel_results.hotel_description[r],
70
+ "hotel_picture":hotel_results.hotel_image[r],
71
+ "relevance score": smallarr.tolist(),
72
+
73
+ })
74
+
75
+ return resultlist
76
+ def search_ares(query):
77
+ x_api_key="ares_e77b47e2754d39b9989a83584d6c528a1980e42ea1f4827eb2584d5b4ee30ccc"
78
+ url = "https://api-ares.traversaal.ai/live/predict"
79
+ payload = {"query": [query]}
80
+ headers = {
81
+ "x-api-key": x_api_key,
82
+ "content-type": "application/json"}
83
+ response = requests.post(url, json=payload, headers=headers)
84
+ content = response.json()
85
+ return content
86
+
87
+
88
+ def greet(name):
89
+ print("Hi! I am your AI assistant.Please let me know your name please.. ")
90
+ return "Hi " + name + "!"
91
+
92
+ #hotel_details = hotel_info(query)
93
+ #hotel_reviews = search(query)
94
+ #return hotel_details,hotel_reviews
95
+
96
+ blocks = gr.Blocks()
97
+ with blocks as demo:
98
+
99
+ greet = gr.Interface(fn=greet, inputs="textbox",title=title, description=head, outputs="textbox")
100
+ hotel_info= gr.Interface(fn=hotel_info, inputs="text",outputs=[gr.components.Textbox(lines=3, label="Write query to search about hotel info")])
101
+ search = gr.Interface(fn=search, inputs="text", outputs=[gr.components.Textbox(lines=3, label="Write query to search about hotel reviews")])
102
+ search_ares= gr.Interface(fn=search_ares, inputs="textbox", outputs=[gr.components.Textbox(lines=3, label="Write query to search using Ares API")])
103
+
104
+
105
+
106
+ demo.launch(share=True,debug=True)
data.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98f0d222e8fcef69188ed5b58c9e257789378546ffc90b78169a81d7f3bb8601
3
+ size 51660046