Pijush2023 commited on
Commit
e878e84
·
verified ·
1 Parent(s): 5be0699

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -55
app.py CHANGED
@@ -911,6 +911,87 @@ def handle_retrieval_mode_change(choice):
911
  return gr.update(interactive=True), gr.update(interactive=True)
912
 
913
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
914
  def fetch_yelp_restaurants():
915
  from serpapi.google_search import GoogleSearch
916
  import os
@@ -926,51 +1007,19 @@ def fetch_yelp_restaurants():
926
  results = search.get_dict()
927
  organic_results = results.get("organic_results", [])
928
 
929
- yelp_html = """
930
- <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Top Restaurants</h2>
931
- <style>
932
- table {
933
- font-family: 'Verdana', sans-serif;
934
- color: #333;
935
- border-collapse: collapse;
936
- width: 100%;
937
- }
938
- th, td {
939
- border: 1px solid #fff !important;
940
- padding: 8px;
941
- }
942
- th {
943
- background-color: #f2f2f2;
944
- color: #333;
945
- text-align: left;
946
- }
947
- tr:hover {
948
- background-color: #f5f5f5;
949
- }
950
- .restaurant-link {
951
- color: #1E90FF;
952
- text-decoration: none;
953
- }
954
- .restaurant-link:hover {
955
- text-decoration: underline;
956
- }
957
- </style>
958
- <table>
959
- <tr>
960
- <th>Name</th>
961
- <th>Rating</th>
962
- <th>Reviews</th>
963
- <th>Phone</th>
964
- <th>Snippet</th>
965
- <th>Services</th>
966
- </tr>
967
- """
968
  for result in organic_results:
969
  name = result.get("title", "No name")
970
  rating = result.get("rating", "No rating")
971
  reviews = result.get("reviews", "No reviews")
972
  phone = result.get("phone", "Not Available")
973
- snippet = result.get("snippet", "No Available")
974
  services = result.get("service_options", "Not Known")
975
 
976
  if isinstance(services, list):
@@ -978,20 +1027,11 @@ def fetch_yelp_restaurants():
978
  elif isinstance(services, dict):
979
  services = ", ".join([f"{key}: {value}" for key, value in services.items()])
980
 
981
- link = result.get("link", "#")
982
-
983
- yelp_html += f"""
984
- <tr>
985
- <td><a class='restaurant-link' href='{link}' target='_blank'>{name}</a></td>
986
- <td>{rating}</td>
987
- <td>{reviews}</td>
988
- <td>{phone}</td>
989
- <td>{snippet}</td>
990
- <td>{services}</td>
991
- </tr>
992
- """
993
- yelp_html += "</table>"
994
- return yelp_html
995
 
996
 
997
 
@@ -1052,7 +1092,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1052
  weather_output = gr.HTML(value=fetch_local_weather())
1053
  news_output = gr.HTML(value=fetch_local_news())
1054
  events_output = gr.HTML(value=fetch_local_events())
1055
- restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
1056
 
1057
 
1058
  with gr.Column():
 
911
  return gr.update(interactive=True), gr.update(interactive=True)
912
 
913
 
914
+ # def fetch_yelp_restaurants():
915
+ # from serpapi.google_search import GoogleSearch
916
+ # import os
917
+
918
+ # params = {
919
+ # "engine": "yelp",
920
+ # "find_desc": "Restaurant",
921
+ # "find_loc": "Birmingham, AL, USA",
922
+ # "api_key": os.getenv("SERP_API")
923
+ # }
924
+
925
+ # search = GoogleSearch(params)
926
+ # results = search.get_dict()
927
+ # organic_results = results.get("organic_results", [])
928
+
929
+ # yelp_html = """
930
+ # <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Top Restaurants</h2>
931
+ # <style>
932
+ # table {
933
+ # font-family: 'Verdana', sans-serif;
934
+ # color: #333;
935
+ # border-collapse: collapse;
936
+ # width: 100%;
937
+ # }
938
+ # th, td {
939
+ # border: 1px solid #fff !important;
940
+ # padding: 8px;
941
+ # }
942
+ # th {
943
+ # background-color: #f2f2f2;
944
+ # color: #333;
945
+ # text-align: left;
946
+ # }
947
+ # tr:hover {
948
+ # background-color: #f5f5f5;
949
+ # }
950
+ # .restaurant-link {
951
+ # color: #1E90FF;
952
+ # text-decoration: none;
953
+ # }
954
+ # .restaurant-link:hover {
955
+ # text-decoration: underline;
956
+ # }
957
+ # </style>
958
+ # <table>
959
+ # <tr>
960
+ # <th>Name</th>
961
+ # <th>Rating</th>
962
+ # <th>Reviews</th>
963
+ # <th>Phone</th>
964
+ # <th>Snippet</th>
965
+ # <th>Services</th>
966
+ # </tr>
967
+ # """
968
+ # for result in organic_results:
969
+ # name = result.get("title", "No name")
970
+ # rating = result.get("rating", "No rating")
971
+ # reviews = result.get("reviews", "No reviews")
972
+ # phone = result.get("phone", "Not Available")
973
+ # snippet = result.get("snippet", "No Available")
974
+ # services = result.get("service_options", "Not Known")
975
+
976
+ # if isinstance(services, list):
977
+ # services = ", ".join(services)
978
+ # elif isinstance(services, dict):
979
+ # services = ", ".join([f"{key}: {value}" for key, value in services.items()])
980
+
981
+ # link = result.get("link", "#")
982
+
983
+ # yelp_html += f"""
984
+ # <tr>
985
+ # <td><a class='restaurant-link' href='{link}' target='_blank'>{name}</a></td>
986
+ # <td>{rating}</td>
987
+ # <td>{reviews}</td>
988
+ # <td>{phone}</td>
989
+ # <td>{snippet}</td>
990
+ # <td>{services}</td>
991
+ # </tr>
992
+ # """
993
+ # yelp_html += "</table>"
994
+ # return yelp_html
995
  def fetch_yelp_restaurants():
996
  from serpapi.google_search import GoogleSearch
997
  import os
 
1007
  results = search.get_dict()
1008
  organic_results = results.get("organic_results", [])
1009
 
1010
+ # Start with a header row
1011
+ yelp_text = "Top Restaurants in Birmingham, AL:\n"
1012
+ yelp_text += "{:<30} {:<10} {:<10} {:<15} {:<40} {:<20}\n".format(
1013
+ "Name", "Rating", "Reviews", "Phone", "Snippet", "Services"
1014
+ )
1015
+ yelp_text += "-"*120 + "\n"
1016
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
  for result in organic_results:
1018
  name = result.get("title", "No name")
1019
  rating = result.get("rating", "No rating")
1020
  reviews = result.get("reviews", "No reviews")
1021
  phone = result.get("phone", "Not Available")
1022
+ snippet = result.get("snippet", "Not Available")
1023
  services = result.get("service_options", "Not Known")
1024
 
1025
  if isinstance(services, list):
 
1027
  elif isinstance(services, dict):
1028
  services = ", ".join([f"{key}: {value}" for key, value in services.items()])
1029
 
1030
+ yelp_text += "{:<30} {:<10} {:<10} {:<15} {:<40} {:<20}\n".format(
1031
+ name, rating, reviews, phone, snippet, services
1032
+ )
1033
+
1034
+ return yelp_text
 
 
 
 
 
 
 
 
 
1035
 
1036
 
1037
 
 
1092
  weather_output = gr.HTML(value=fetch_local_weather())
1093
  news_output = gr.HTML(value=fetch_local_news())
1094
  events_output = gr.HTML(value=fetch_local_events())
1095
+ # restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
1096
 
1097
 
1098
  with gr.Column():