Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -149,27 +149,66 @@ with gr.Blocks(css="""
|
|
149 |
font-weight: 600;
|
150 |
text-align: center;
|
151 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
""") as demo:
|
|
|
153 |
gr.HTML(elem_classes="title", value="๐")
|
154 |
gr.HTML("<img src='https://see.fontimg.com/api/rf5/JpZqa/MWMyNzc2ODk3OTFlNDk2OWJkY2VjYTIzNzFlY2E4MWIudHRm/bm9tYWQgZGVzdGluYXRpb25z/super-feel.png?r=fs&h=130&w=2000&fg=e2e2e2&bg=FFFFFF&tb=1&s=65' alt='Graffiti fonts'></a>")
|
155 |
|
156 |
-
gr.Markdown("
|
157 |
|
|
|
158 |
with gr.Row():
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
data_table = gr.Dataframe(
|
175 |
value=styled_df,
|
@@ -208,7 +247,170 @@ with gr.Blocks(css="""
|
|
208 |
|
209 |
return style_dataframe(filtered_df)
|
210 |
|
211 |
-
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
demo.launch()
|
|
|
149 |
font-weight: 600;
|
150 |
text-align: center;
|
151 |
}
|
152 |
+
|
153 |
+
.app-subtitle {
|
154 |
+
color: rgba(255, 255, 255, 0.8);
|
155 |
+
font-size: 1.2rem;
|
156 |
+
margin-bottom: 15px;
|
157 |
+
}
|
158 |
+
|
159 |
""") as demo:
|
160 |
+
# Remove header container and directly show title and subtitle with regular markdown
|
161 |
gr.HTML(elem_classes="title", value="๐")
|
162 |
gr.HTML("<img src='https://see.fontimg.com/api/rf5/JpZqa/MWMyNzc2ODk3OTFlNDk2OWJkY2VjYTIzNzFlY2E4MWIudHRm/bm9tYWQgZGVzdGluYXRpb25z/super-feel.png?r=fs&h=130&w=2000&fg=e2e2e2&bg=FFFFFF&tb=1&s=65' alt='Graffiti fonts'></a>")
|
163 |
|
164 |
+
gr.Markdown("Discover the best places for digital nomads around the globe")
|
165 |
|
166 |
+
# Remove the separate row for basic filters and integrate all filters into one section
|
167 |
with gr.Row():
|
168 |
+
with gr.Column(scale=1):
|
169 |
+
# Group all sliders together
|
170 |
+
cost_slider = gr.Slider(
|
171 |
+
minimum=500,
|
172 |
+
maximum=4000,
|
173 |
+
value=4000,
|
174 |
+
step=100,
|
175 |
+
label="๐ฐ Maximum Monthly Cost of Living (USD)"
|
176 |
+
)
|
177 |
+
|
178 |
+
min_internet = gr.Slider(
|
179 |
+
minimum=0,
|
180 |
+
maximum=400,
|
181 |
+
value=0,
|
182 |
+
step=10,
|
183 |
+
label="๐ Minimum Internet Speed (Mbps)"
|
184 |
+
)
|
185 |
+
|
186 |
+
min_quality = gr.Slider(
|
187 |
+
minimum=5,
|
188 |
+
maximum=10,
|
189 |
+
value=5,
|
190 |
+
step=0.1,
|
191 |
+
label="โญ Minimum Quality of Life"
|
192 |
+
)
|
193 |
|
194 |
+
with gr.Column(scale=1):
|
195 |
+
# Put country dropdown with the checkboxes
|
196 |
+
country_dropdown = gr.Dropdown(
|
197 |
+
choices=get_country_with_emoji("Country"),
|
198 |
+
value="โ๏ธ All",
|
199 |
+
label="๐ Filter by Country"
|
200 |
+
)
|
201 |
+
|
202 |
+
# Group all checkboxes together
|
203 |
+
visa_filter = gr.CheckboxGroup(
|
204 |
+
choices=["Has Digital Nomad Visa", "Visa Length โฅ 12 Months"],
|
205 |
+
label="๐ Visa Requirements"
|
206 |
+
)
|
207 |
+
|
208 |
+
special_features = gr.CheckboxGroup(
|
209 |
+
choices=["Coastal Cities", "Cultural Hotspots", "Affordable (<$1000/month)"],
|
210 |
+
label="โจ Special Features"
|
211 |
+
)
|
212 |
|
213 |
data_table = gr.Dataframe(
|
214 |
value=styled_df,
|
|
|
247 |
|
248 |
return style_dataframe(filtered_df)
|
249 |
|
250 |
+
# Define advanced filters function
|
251 |
+
def apply_advanced_filters(country, cost, min_internet_speed, min_qol, visa_reqs, features):
|
252 |
+
# Process country filter
|
253 |
+
if country and country.startswith("โ๏ธ All"):
|
254 |
+
country = "All"
|
255 |
+
else:
|
256 |
+
for emoji_code in ["๐ง๐ท", "๐ญ๐บ", "๐บ๐พ", "๐ต๐น", "๐ฌ๐ช", "๐น๐ญ", "๐ฆ๐ช", "๐ช๐ธ", "๐ฎ๐น", "๐จ๐ฆ", "๐จ๐ด", "๐ฒ๐ฝ", "๐ฏ๐ต", "๐ฐ๐ท"]:
|
257 |
+
if country and emoji_code in country:
|
258 |
+
country = country.split(" ", 1)[1]
|
259 |
+
break
|
260 |
+
|
261 |
+
filtered_df = df.copy()
|
262 |
+
|
263 |
+
# Basic filters (country and cost)
|
264 |
+
if country and country != "All":
|
265 |
+
filtered_df = filtered_df[filtered_df["Country"] == country]
|
266 |
+
|
267 |
+
if cost < df["Monthly Cost Living (USD)"].max():
|
268 |
+
cost_mask = (filtered_df["Monthly Cost Living (USD)"] <= cost) & (filtered_df["Monthly Cost Living (USD)"].notna())
|
269 |
+
filtered_df = filtered_df[cost_mask]
|
270 |
+
|
271 |
+
# Advanced filters
|
272 |
+
# Internet speed filter
|
273 |
+
if min_internet_speed > 0:
|
274 |
+
filtered_df = filtered_df[filtered_df["Internet Speed (Mbps)"] >= min_internet_speed]
|
275 |
+
|
276 |
+
# Quality of life filter
|
277 |
+
if min_qol > 5:
|
278 |
+
filtered_df = filtered_df[filtered_df["Quality of Life"] >= min_qol]
|
279 |
+
|
280 |
+
# Visa filters
|
281 |
+
if "Has Digital Nomad Visa" in visa_reqs:
|
282 |
+
filtered_df = filtered_df[filtered_df["Digital Nomad Visa"] == "Yes"]
|
283 |
+
|
284 |
+
if "Visa Length โฅ 12 Months" in visa_reqs:
|
285 |
+
filtered_df = filtered_df[filtered_df["Visa Length (Months)"] >= 12]
|
286 |
+
|
287 |
+
# Special features filters
|
288 |
+
if "Coastal Cities" in features:
|
289 |
+
coastal_keywords = ["coast", "beach", "sea", "ocean"]
|
290 |
+
mask = filtered_df["Key Feature"].str.contains("|".join(coastal_keywords), case=False, na=False)
|
291 |
+
filtered_df = filtered_df[mask]
|
292 |
+
|
293 |
+
if "Cultural Hotspots" in features:
|
294 |
+
cultural_keywords = ["cultur", "art", "histor", "heritage"]
|
295 |
+
mask = filtered_df["Key Feature"].str.contains("|".join(cultural_keywords), case=False, na=False)
|
296 |
+
filtered_df = filtered_df[mask]
|
297 |
+
|
298 |
+
if "Affordable (<$1000/month)" in features:
|
299 |
+
filtered_df = filtered_df[filtered_df["Monthly Cost Living (USD)"] < 1000]
|
300 |
+
|
301 |
+
return style_dataframe(filtered_df)
|
302 |
|
303 |
+
# Connect all filters to use the advanced filter function
|
304 |
+
country_dropdown.change(
|
305 |
+
apply_advanced_filters,
|
306 |
+
[country_dropdown, cost_slider, min_internet, min_quality, visa_filter, special_features],
|
307 |
+
data_table
|
308 |
+
)
|
309 |
+
cost_slider.change(
|
310 |
+
apply_advanced_filters,
|
311 |
+
[country_dropdown, cost_slider, min_internet, min_quality, visa_filter, special_features],
|
312 |
+
data_table
|
313 |
+
)
|
314 |
+
min_internet.change(
|
315 |
+
apply_advanced_filters,
|
316 |
+
[country_dropdown, cost_slider, min_internet, min_quality, visa_filter, special_features],
|
317 |
+
data_table
|
318 |
+
)
|
319 |
+
min_quality.change(
|
320 |
+
apply_advanced_filters,
|
321 |
+
[country_dropdown, cost_slider, min_internet, min_quality, visa_filter, special_features],
|
322 |
+
data_table
|
323 |
+
)
|
324 |
+
visa_filter.change(
|
325 |
+
apply_advanced_filters,
|
326 |
+
[country_dropdown, cost_slider, min_internet, min_quality, visa_filter, special_features],
|
327 |
+
data_table
|
328 |
+
)
|
329 |
+
special_features.change(
|
330 |
+
apply_advanced_filters,
|
331 |
+
[country_dropdown, cost_slider, min_internet, min_quality, visa_filter, special_features],
|
332 |
+
data_table
|
333 |
+
)
|
334 |
+
|
335 |
+
with gr.Row():
|
336 |
+
with gr.Column(scale=1):
|
337 |
+
gr.Markdown("### ๐งณ Digital Nomad Tips")
|
338 |
+
gr.Markdown("- Look for places with digital nomad visas for longer stays \n"
|
339 |
+
"- Consider internet speed if you need to attend video meetings \n"
|
340 |
+
"- Balance cost of living with quality of life for the best experience \n"
|
341 |
+
"- Some newer nomad destinations may have incomplete data")
|
342 |
+
|
343 |
+
|
344 |
+
gr.Markdown("### ๐ฏ Find Your Ideal Destination")
|
345 |
+
with gr.Row():
|
346 |
+
with gr.Column():
|
347 |
+
priority = gr.CheckboxGroup(
|
348 |
+
["Best Quality of Life", "Fastest Internet", "Most Affordable", "Balance of All Factors"],
|
349 |
+
label="What are Your Priorities?",
|
350 |
+
value=["Balance of All Factors"]
|
351 |
+
)
|
352 |
+
|
353 |
+
find_btn = gr.Button("Find My Ideal Destination", variant="primary")
|
354 |
+
|
355 |
+
recommendation = gr.Textbox(label="Recommended Location", lines=3)
|
356 |
+
|
357 |
+
def recommend_location(priorities, max_budget):
|
358 |
+
if not priorities:
|
359 |
+
return "Please select at least one priority to get a recommendation."
|
360 |
+
|
361 |
+
# Filter by budget first
|
362 |
+
budget_filtered_df = df[df["Monthly Cost Living (USD)"] <= max_budget]
|
363 |
+
|
364 |
+
# If no cities match the budget, use the full dataset but mention it
|
365 |
+
budget_warning = ""
|
366 |
+
if len(budget_filtered_df) == 0:
|
367 |
+
budget_filtered_df = df
|
368 |
+
budget_warning = "โ ๏ธ No cities match your budget. Showing best options regardless of cost.\n\n"
|
369 |
+
|
370 |
+
recommendations = []
|
371 |
+
|
372 |
+
if "Best Quality of Life" in priorities:
|
373 |
+
top_city = budget_filtered_df.sort_values("Quality of Life", ascending=False).iloc[0]
|
374 |
+
message = f"๐ {top_city['City']}, {top_city['Country']} - Quality of Life: {top_city['Quality of Life']}\n"
|
375 |
+
message += f"Monthly Cost: ${top_city['Monthly Cost Living (USD)']}\n"
|
376 |
+
message += f"Key Feature: {top_city['Key Feature']}"
|
377 |
+
recommendations.append(message)
|
378 |
+
|
379 |
+
if "Fastest Internet" in priorities:
|
380 |
+
top_city = budget_filtered_df.sort_values("Internet Speed (Mbps)", ascending=False).iloc[0]
|
381 |
+
message = f"๐ {top_city['City']}, {top_city['Country']} - Internet Speed: {top_city['Internet Speed (Mbps)']} Mbps\n"
|
382 |
+
message += f"Monthly Cost: ${top_city['Monthly Cost Living (USD)']}\n"
|
383 |
+
message += f"Key Feature: {top_city['Key Feature']}"
|
384 |
+
recommendations.append(message)
|
385 |
+
|
386 |
+
if "Most Affordable" in priorities:
|
387 |
+
top_city = budget_filtered_df.sort_values("Monthly Cost Living (USD)", ascending=True).iloc[0]
|
388 |
+
message = f"๐ฐ {top_city['City']}, {top_city['Country']} - Monthly Cost: ${top_city['Monthly Cost Living (USD)']}\n"
|
389 |
+
message += f"Quality of Life: {top_city['Quality of Life']}, Internet: {top_city['Internet Speed (Mbps)']} Mbps\n"
|
390 |
+
message += f"Key Feature: {top_city['Key Feature']}"
|
391 |
+
recommendations.append(message)
|
392 |
+
|
393 |
+
if "Balance of All Factors" in priorities:
|
394 |
+
# Create a composite score
|
395 |
+
df_temp = budget_filtered_df.copy()
|
396 |
+
# Normalize and weight each factor
|
397 |
+
df_temp['quality_norm'] = df_temp['Quality of Life'] / 10
|
398 |
+
df_temp['internet_norm'] = df_temp['Internet Speed (Mbps)'] / 400
|
399 |
+
df_temp['cost_norm'] = 1 - (df_temp['Monthly Cost Living (USD)'] / 4000)
|
400 |
+
|
401 |
+
df_temp['composite_score'] = (df_temp['quality_norm'] + df_temp['internet_norm'] + df_temp['cost_norm']) / 3
|
402 |
+
top_city = df_temp.sort_values("composite_score", ascending=False).iloc[0]
|
403 |
+
|
404 |
+
message = f"โจ {top_city['City']}, {top_city['Country']} - Balanced Choice\n"
|
405 |
+
message += f"Quality: {top_city['Quality of Life']}, Internet: {top_city['Internet Speed (Mbps)']} Mbps, Cost: ${top_city['Monthly Cost Living (USD)']}\n"
|
406 |
+
message += f"Key Feature: {top_city['Key Feature']}"
|
407 |
+
recommendations.append(message)
|
408 |
+
|
409 |
+
return budget_warning + "\n\n".join(recommendations)
|
410 |
+
|
411 |
+
find_btn.click(recommend_location, inputs=[priority, cost_slider], outputs=recommendation)
|
412 |
+
|
413 |
+
# Also update when budget slider changes
|
414 |
+
cost_slider.change(recommend_location, inputs=[priority, cost_slider], outputs=recommendation)
|
415 |
+
|
416 |
demo.launch()
|