Update app.py
Browse files
app.py
CHANGED
|
@@ -137,16 +137,23 @@ def find_nearby(place=None):
|
|
| 137 |
print("The 5 closest locations are:\n")
|
| 138 |
print(closest_hotels)
|
| 139 |
return closest_hotels
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
@spaces.GPU
|
| 141 |
# Define the respond function
|
| 142 |
def search_hotel(place=None):
|
| 143 |
df_found = find_nearby(place)
|
| 144 |
if df_found is None:
|
| 145 |
return pd.DataFrame()
|
| 146 |
-
|
|
|
|
| 147 |
hotel_ids = df_found["hotel_id"].values.tolist()
|
| 148 |
filtered_df = df_hotels[df_hotels['hotel_id'].isin(hotel_ids)]
|
| 149 |
-
|
|
|
|
|
|
|
| 150 |
filtered_df = filtered_df.sort_values('hotel_id').reset_index(drop=True)
|
| 151 |
grouped_df = filtered_df.groupby('hotel_id', observed=True).head(2)
|
| 152 |
description_data = []
|
|
@@ -169,6 +176,7 @@ def search_hotel(place=None):
|
|
| 169 |
|
| 170 |
return pd.DataFrame(description_data)
|
| 171 |
|
|
|
|
| 172 |
def show_hotels(place=None):
|
| 173 |
description_df = search_hotel(place)
|
| 174 |
if description_df.empty:
|
|
|
|
| 137 |
print("The 5 closest locations are:\n")
|
| 138 |
print(closest_hotels)
|
| 139 |
return closest_hotels
|
| 140 |
+
|
| 141 |
+
# Suppress InsecureRequestWarning
|
| 142 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 143 |
+
|
| 144 |
@spaces.GPU
|
| 145 |
# Define the respond function
|
| 146 |
def search_hotel(place=None):
|
| 147 |
df_found = find_nearby(place)
|
| 148 |
if df_found is None:
|
| 149 |
return pd.DataFrame()
|
| 150 |
+
|
| 151 |
+
df_found = df_found.head(3) # Only last 3 hotels, to save runtime.
|
| 152 |
hotel_ids = df_found["hotel_id"].values.tolist()
|
| 153 |
filtered_df = df_hotels[df_hotels['hotel_id'].isin(hotel_ids)]
|
| 154 |
+
|
| 155 |
+
# Use .loc[] to avoid SettingWithCopyWarning
|
| 156 |
+
filtered_df.loc[:, 'hotel_id'] = pd.Categorical(filtered_df['hotel_id'], categories=hotel_ids, ordered=True)
|
| 157 |
filtered_df = filtered_df.sort_values('hotel_id').reset_index(drop=True)
|
| 158 |
grouped_df = filtered_df.groupby('hotel_id', observed=True).head(2)
|
| 159 |
description_data = []
|
|
|
|
| 176 |
|
| 177 |
return pd.DataFrame(description_data)
|
| 178 |
|
| 179 |
+
|
| 180 |
def show_hotels(place=None):
|
| 181 |
description_df = search_hotel(place)
|
| 182 |
if description_df.empty:
|