Pijush2023 commited on
Commit
6a44ec2
·
verified ·
1 Parent(s): 117f257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -99
app.py CHANGED
@@ -302,100 +302,6 @@ def bot(history, choice, tts_choice, retrieval_mode):
302
 
303
  history.append([response, None]) # Ensure the response is added in the correct format
304
 
305
- import os
306
- from serpapi.google_search import GoogleSearch
307
-
308
-
309
- def fetch_restaurant_details(location):
310
- params = {
311
- "engine": "yelp",
312
- "find_desc": "Restaurant",
313
- "find_loc": location,
314
- "api_key": os.getenv("SERP_API")
315
- }
316
-
317
- search = GoogleSearch(params)
318
- results = search.get_dict()
319
- organic_results = results.get("organic_results", [])
320
-
321
- yelp_html = """
322
- <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Top Restaurants in {}</h2>
323
- <style>
324
- table {{
325
- font-family: 'Verdana', sans-serif;
326
- color: #333;
327
- border-collapse: collapse;
328
- width: 100%;
329
- }}
330
- th, td {{
331
- border: 1px solid #fff !important;
332
- padding: 8px;
333
- }}
334
- th {{
335
- background-color: #f2f2f2;
336
- color: #333;
337
- text-align: left;
338
- }}
339
- tr:hover {{
340
- background-color: #f5f5f5;
341
- }}
342
- .restaurant-link {{
343
- color: #1E90FF;
344
- text-decoration: none;
345
- }}
346
- .restaurant-link:hover {{
347
- text-decoration: underline;
348
- }}
349
- </style>
350
- <table>
351
- <tr>
352
- <th>Name</th>
353
- <th>Rating</th>
354
- <th>Reviews</th>
355
- <th>Phone</th>
356
- <th>Snippet</th>
357
- <th>Services</th>
358
- </tr>
359
- """.format(location)
360
-
361
- for result in organic_results:
362
- name = result.get("title", "No name")
363
- rating = result.get("rating", "No rating")
364
- reviews = result.get("reviews", "No reviews")
365
- phone = result.get("phone", "Not Available")
366
- snippet = result.get("snippet", "No Available")
367
- services = result.get("service_options", "Not Known")
368
-
369
- if isinstance(services, list):
370
- services = ", ".join(services)
371
- elif isinstance(services, dict):
372
- services = ", ".join([f"{key}: {value}" for key, value in services.items()])
373
-
374
- link = result.get("link", "#")
375
-
376
- yelp_html += f"""
377
- <tr>
378
- <td><a class='restaurant-link' href='{link}' target='_blank'>{name}</a></td>
379
- <td>{rating}</td>
380
- <td>{reviews}</td>
381
- <td>{phone}</td>
382
- <td>{snippet}</td>
383
- <td>{services}</td>
384
- </tr>
385
- """
386
-
387
- yelp_html += "</table>"
388
- return yelp_html
389
-
390
- def restaurant_search_agent(query):
391
- if "restaurant" in query.lower():
392
- location = "Birmingham, AL, USA" # You can customize this based on user input or other logic
393
- return fetch_restaurant_details(location)
394
- else:
395
- return "This agent only handles restaurant queries."
396
-
397
-
398
-
399
 
400
 
401
  def add_message(history, message):
@@ -1044,11 +950,11 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1044
  # Handle retrieval mode change
1045
  retrieval_mode.change(fn=handle_retrieval_mode_change, inputs=retrieval_mode, outputs=[choice, choice])
1046
 
1047
- # with gr.Column():
1048
- # weather_output = gr.HTML(value=fetch_local_weather())
1049
- # news_output = gr.HTML(value=fetch_local_news())
1050
- # events_output = gr.HTML(value=fetch_local_events())
1051
- # restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
1052
 
1053
 
1054
  with gr.Column():
 
302
 
303
  history.append([response, None]) # Ensure the response is added in the correct format
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
 
306
 
307
  def add_message(history, message):
 
950
  # Handle retrieval mode change
951
  retrieval_mode.change(fn=handle_retrieval_mode_change, inputs=retrieval_mode, outputs=[choice, choice])
952
 
953
+ with gr.Column():
954
+ weather_output = gr.HTML(value=fetch_local_weather())
955
+ news_output = gr.HTML(value=fetch_local_news())
956
+ events_output = gr.HTML(value=fetch_local_events())
957
+ restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
958
 
959
 
960
  with gr.Column():