Spaces:
Build error
Build error
Pavel Duchovny
commited on
Commit
·
f937f4c
1
Parent(s):
0e4cc22
init
Browse files- app.py +17 -5
- iframe.html +1 -0
app.py
CHANGED
|
@@ -41,20 +41,30 @@ def get_restaurants(search, location, meters):
|
|
| 41 |
model="gpt-3.5-turbo",
|
| 42 |
messages=[
|
| 43 |
{"role": "system", "content": "You are a helpful restaurant assistant."},
|
| 44 |
-
{ "role": "user", "content": f"Find me the 2 best restaurant and why based on {search} and {restaurant_docs}. explain trades offs and why I should go to each one."}
|
| 45 |
]
|
| 46 |
)
|
| 47 |
|
| 48 |
trips_collection.delete_many({"searchTrip": newTrip})
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
def pre_aggregate_meters(location, meters):
|
| 54 |
|
| 55 |
tripId = ObjectId()
|
| 56 |
|
| 57 |
-
restaurants_collection.aggregate([
|
| 58 |
{
|
| 59 |
"$geoNear": {
|
| 60 |
"near": location,
|
|
@@ -76,6 +86,8 @@ def pre_aggregate_meters(location, meters):
|
|
| 76 |
}
|
| 77 |
]);
|
| 78 |
|
|
|
|
|
|
|
| 79 |
sleep(10)
|
| 80 |
|
| 81 |
return tripId
|
|
@@ -87,7 +99,7 @@ with gr.Blocks() as demo:
|
|
| 87 |
# MongoDB's Vector Restaurant planner
|
| 88 |
Start typing below to see the results
|
| 89 |
""")
|
| 90 |
-
gr.HTML(value='<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="640" height="480" src="https://charts.mongodb.com/charts-paveldev-wiumf/embed/charts?id=65c24b0c-2215-4e6f-829c-f484dfd8a90c&maxDataAge=3600&theme=light&autoRefresh=true"></iframe>')
|
| 91 |
#
|
| 92 |
gr.Interface(
|
| 93 |
get_restaurants,
|
|
@@ -111,7 +123,7 @@ with gr.Blocks() as demo:
|
|
| 111 |
]
|
| 112 |
})], label="Location", info="What location you need?"),
|
| 113 |
gr.Slider(minimum=500, maximum=10000, randomize=False, step=5, label="Radius in meters")],
|
| 114 |
-
gr.Textbox(label="MongoDB Vector Recommendations", placeholder="Results will be displayed here"),
|
| 115 |
|
| 116 |
)
|
| 117 |
#radio.change(location_searched, loc, out)
|
|
|
|
| 41 |
model="gpt-3.5-turbo",
|
| 42 |
messages=[
|
| 43 |
{"role": "system", "content": "You are a helpful restaurant assistant."},
|
| 44 |
+
{ "role": "user", "content": f"Find me the 2 best restaurant and why based on {search} and {restaurant_docs}. explain trades offs and why I should go to each one. You can mention the third option as a possible alternative."}
|
| 45 |
]
|
| 46 |
)
|
| 47 |
|
| 48 |
trips_collection.delete_many({"searchTrip": newTrip})
|
| 49 |
|
| 50 |
+
first_restaurant = restaurant_docs[0]['restaurant_id']
|
| 51 |
+
second_restaurant = restaurant_docs[1]['restaurant_id']
|
| 52 |
+
third_restaurant = restaurant_docs[2]['restaurant_id']
|
| 53 |
+
|
| 54 |
+
if (first_restaurant or second_restaurant or third_restaurant) is None:
|
| 55 |
+
return "No restaurants found", '<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="640" height="480" src="https://charts.mongodb.com/charts-paveldev-wiumf/embed/charts?id=65c24b0c-2215-4e6f-829c-f484dfd8a90c&filter={\'restaurant_id\':\'\'}&maxDataAge=3600&theme=light&autoRefresh=true"></iframe>'
|
| 56 |
+
else:
|
| 57 |
+
restaurant_string = f"\'{first_restaurant}\', \'{second_restaurant}\', \'{third_restaurant}\'"
|
| 58 |
+
iframe = '<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="640" height="480" src="https://charts.mongodb.com/charts-paveldev-wiumf/embed/charts?id=65c24b0c-2215-4e6f-829c-f484dfd8a90c&filter={\'restaurant_id\':{$in:[' + restaurant_string + ']}}&maxDataAge=3600&theme=light&autoRefresh=true"></iframe>'
|
| 59 |
+
|
| 60 |
+
return chat_response.choices[0].message.content, iframe
|
| 61 |
|
| 62 |
|
| 63 |
def pre_aggregate_meters(location, meters):
|
| 64 |
|
| 65 |
tripId = ObjectId()
|
| 66 |
|
| 67 |
+
result = restaurants_collection.aggregate([
|
| 68 |
{
|
| 69 |
"$geoNear": {
|
| 70 |
"near": location,
|
|
|
|
| 86 |
}
|
| 87 |
]);
|
| 88 |
|
| 89 |
+
print(result)
|
| 90 |
+
print(trips_collection.count_documents({"searchTrip": tripId}));
|
| 91 |
sleep(10)
|
| 92 |
|
| 93 |
return tripId
|
|
|
|
| 99 |
# MongoDB's Vector Restaurant planner
|
| 100 |
Start typing below to see the results
|
| 101 |
""")
|
| 102 |
+
#gr.HTML(value='<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="640" height="480" src="https://charts.mongodb.com/charts-paveldev-wiumf/embed/charts?id=65c24b0c-2215-4e6f-829c-f484dfd8a90c&maxDataAge=3600&theme=light&autoRefresh=true"></iframe>')
|
| 103 |
#
|
| 104 |
gr.Interface(
|
| 105 |
get_restaurants,
|
|
|
|
| 123 |
]
|
| 124 |
})], label="Location", info="What location you need?"),
|
| 125 |
gr.Slider(minimum=500, maximum=10000, randomize=False, step=5, label="Radius in meters")],
|
| 126 |
+
[gr.Textbox(label="MongoDB Vector Recommendations", placeholder="Results will be displayed here"), "html"],
|
| 127 |
|
| 128 |
)
|
| 129 |
#radio.change(location_searched, loc, out)
|
iframe.html
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<iframe style="background: #FFFFFF;border: none;border-radius: 2px;box-shadow: 0 2px 10px 0 rgba(70, 76, 79, .2);" width="640" height="480" src="https://charts.mongodb.com/charts-paveldev-wiumf/embed/charts?id=65c24b0c-2215-4e6f-829c-f484dfd8a90c&filter={'restaurant_id':{$in:['50005104', '41166347', '41314543']}}&maxDataAge=3600&theme=light&autoRefresh=true"></iframe>
|