Pijush2023 commited on
Commit
bc13b2c
·
verified ·
1 Parent(s): 35dedb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -14
app.py CHANGED
@@ -967,41 +967,59 @@ def fetch_yelp_restaurants():
967
 
968
  return response_text
969
 
970
- def fetch_hotels_in_birmingham():
971
  params = {
972
  "engine": "google_hotels",
973
- "q": "Hotels in Birmingham, AL",
974
  "check_in_date": "2024-08-14",
975
  "check_out_date": "2024-08-15",
976
  "adults": "2",
977
  "currency": "USD",
978
  "gl": "us",
979
  "hl": "en",
980
- "api_key": os.getenv("SERP_API")
981
  }
982
 
983
  search = GoogleSearch(params)
984
  results = search.get_dict()
985
  hotels = results.get("organic_results", [])
986
 
987
- response_text = ""
988
-
989
- for hotel in hotels[:5]: # Limiting to top 5 hotels
 
 
 
 
 
 
 
 
 
 
 
990
  name = hotel.get("title", "No name")
991
  rating = hotel.get("rating", "No rating")
992
  reviews = hotel.get("reviews", "No reviews")
993
  price = hotel.get("price", "No price")
994
- location = f"{name}, Birmingham, AL"
995
  link = hotel.get("link", "#")
 
996
 
997
- # Format the output for each hotel
998
- response_text += f"[{name}]({link})\n"
999
- response_text += f"*{location}*\n"
1000
- response_text += f"**Price:** {price}\n"
1001
- response_text += f"**Rating:** {rating} ({reviews} reviews)\n"
1002
- response_text += "-" * 50 + "\n"
 
 
 
 
 
1003
 
1004
- return response_text
 
 
1005
 
1006
 
1007
 
@@ -1071,6 +1089,8 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1071
  news_output = gr.HTML(value=fetch_local_news())
1072
  events_output = gr.HTML(value=fetch_local_events())
1073
  # restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
 
 
1074
 
1075
 
1076
  with gr.Column():
 
967
 
968
  return response_text
969
 
970
+ def fetch_and_display_hotels():
971
  params = {
972
  "engine": "google_hotels",
973
+ "q": "Bali Resorts",
974
  "check_in_date": "2024-08-14",
975
  "check_out_date": "2024-08-15",
976
  "adults": "2",
977
  "currency": "USD",
978
  "gl": "us",
979
  "hl": "en",
980
+ "api_key": "74972e6cc9f9e092bd86764a78f7d18c1d71b156eca8b1fe7fd65c2406cfb588"
981
  }
982
 
983
  search = GoogleSearch(params)
984
  results = search.get_dict()
985
  hotels = results.get("organic_results", [])
986
 
987
+ # Create an HTML table
988
+ table_html = """
989
+ <table style="width:100%; border-collapse: collapse; font-family: Arial, sans-serif;">
990
+ <tr style="background-color: #f2f2f2;">
991
+ <th style="padding: 8px; border: 1px solid #ddd;">Name</th>
992
+ <th style="padding: 8px; border: 1px solid #ddd;">Location</th>
993
+ <th style="padding: 8px; border: 1px solid #ddd;">Rating</th>
994
+ <th style="padding: 8px; border: 1px solid #ddd;">Reviews</th>
995
+ <th style="padding: 8px; border: 1px solid #ddd;">Price</th>
996
+ <th style="padding: 8px; border: 1px solid #ddd;">Link</th>
997
+ </tr>
998
+ """
999
+
1000
+ for hotel in hotels:
1001
  name = hotel.get("title", "No name")
1002
  rating = hotel.get("rating", "No rating")
1003
  reviews = hotel.get("reviews", "No reviews")
1004
  price = hotel.get("price", "No price")
 
1005
  link = hotel.get("link", "#")
1006
+ location = f"{name}, Birmingham, AL"
1007
 
1008
+ # Add each hotel as a row in the table
1009
+ table_html += f"""
1010
+ <tr>
1011
+ <td style="padding: 8px; border: 1px solid #ddd;">{name}</td>
1012
+ <td style="padding: 8px; border: 1px solid #ddd;">{location}</td>
1013
+ <td style="padding: 8px; border: 1px solid #ddd;">{rating}</td>
1014
+ <td style="padding: 8px; border: 1px solid #ddd;">{reviews}</td>
1015
+ <td style="padding: 8px; border: 1px solid #ddd;">{price}</td>
1016
+ <td style="padding: 8px; border: 1px solid #ddd;"><a href="{link}" target="_blank">View</a></td>
1017
+ </tr>
1018
+ """
1019
 
1020
+ table_html += "</table>"
1021
+
1022
+ return table_html
1023
 
1024
 
1025
 
 
1089
  news_output = gr.HTML(value=fetch_local_news())
1090
  events_output = gr.HTML(value=fetch_local_events())
1091
  # restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
1092
+ gr.Markdown("<h3>Hotel Search Results</h3>")
1093
+ hotel_output = gr.HTML(value=fetch_and_display_hotels())
1094
 
1095
 
1096
  with gr.Column():