Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1333,63 +1333,76 @@ def create_interface():
|
|
| 1333 |
outputs=regression_results
|
| 1334 |
)
|
| 1335 |
|
|
|
|
| 1336 |
with gr.Tab("Typhoon Path Animation"):
|
| 1337 |
with gr.Row():
|
| 1338 |
-
|
| 1339 |
-
initial_years = sorted([year for year in range(1950, 2025) if ibtracs and year in ibtracs.data.keys()])
|
| 1340 |
-
initial_year = initial_years[-1] if initial_years else 2024
|
| 1341 |
-
|
| 1342 |
year_dropdown = gr.Dropdown(
|
| 1343 |
-
choices=
|
| 1344 |
-
value=
|
| 1345 |
label="Year"
|
| 1346 |
)
|
| 1347 |
|
| 1348 |
-
# Initialize typhoons for the initial year
|
| 1349 |
-
initial_typhoons = get_typhoons_for_year(initial_year)
|
| 1350 |
typhoon_dropdown = gr.Dropdown(
|
| 1351 |
-
choices=[
|
| 1352 |
-
|
| 1353 |
-
label="Typhoon",
|
| 1354 |
-
interactive=True
|
| 1355 |
)
|
| 1356 |
-
|
| 1357 |
-
standard_dropdown = gr.
|
| 1358 |
choices=["atlantic", "taiwan"],
|
| 1359 |
value="atlantic",
|
| 1360 |
label="Classification Standard"
|
| 1361 |
)
|
| 1362 |
|
| 1363 |
-
#
|
| 1364 |
-
def
|
| 1365 |
-
if
|
| 1366 |
-
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1367 |
|
| 1368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1369 |
if not typhoons:
|
| 1370 |
-
return []
|
| 1371 |
|
| 1372 |
-
# Return simple list for older Gradio versions
|
| 1373 |
return [name for name, _ in typhoons]
|
| 1374 |
|
|
|
|
| 1375 |
year_dropdown.change(
|
| 1376 |
-
|
| 1377 |
inputs=year_dropdown,
|
| 1378 |
outputs=typhoon_dropdown
|
| 1379 |
)
|
| 1380 |
|
| 1381 |
-
|
|
|
|
| 1382 |
|
| 1383 |
-
|
|
|
|
| 1384 |
|
| 1385 |
-
|
| 1386 |
create_typhoon_path_animation,
|
| 1387 |
inputs=[year_dropdown, typhoon_dropdown, standard_dropdown],
|
| 1388 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1389 |
)
|
| 1390 |
|
| 1391 |
-
return demo
|
| 1392 |
-
|
| 1393 |
# Run the app
|
| 1394 |
if __name__ == "__main__":
|
| 1395 |
# For Hugging Face, use a simpler version without threading
|
|
|
|
| 1333 |
outputs=regression_results
|
| 1334 |
)
|
| 1335 |
|
| 1336 |
+
|
| 1337 |
with gr.Tab("Typhoon Path Animation"):
|
| 1338 |
with gr.Row():
|
| 1339 |
+
# Use default values first, we'll populate after data loads
|
|
|
|
|
|
|
|
|
|
| 1340 |
year_dropdown = gr.Dropdown(
|
| 1341 |
+
choices=[2020, 2021, 2022, 2023, 2024],
|
| 1342 |
+
value=2023,
|
| 1343 |
label="Year"
|
| 1344 |
)
|
| 1345 |
|
|
|
|
|
|
|
| 1346 |
typhoon_dropdown = gr.Dropdown(
|
| 1347 |
+
choices=["Select a year first"],
|
| 1348 |
+
label="Typhoon"
|
|
|
|
|
|
|
| 1349 |
)
|
| 1350 |
+
|
| 1351 |
+
standard_dropdown = gr.Radio(
|
| 1352 |
choices=["atlantic", "taiwan"],
|
| 1353 |
value="atlantic",
|
| 1354 |
label="Classification Standard"
|
| 1355 |
)
|
| 1356 |
|
| 1357 |
+
# Function to populate year dropdown
|
| 1358 |
+
def populate_years():
|
| 1359 |
+
if ibtracs is None:
|
| 1360 |
+
return [2020, 2021, 2022, 2023, 2024]
|
| 1361 |
+
|
| 1362 |
+
available_years = []
|
| 1363 |
+
for year in range(1950, 2025):
|
| 1364 |
+
if year in ibtracs.data:
|
| 1365 |
+
available_years.append(year)
|
| 1366 |
|
| 1367 |
+
return sorted(available_years, reverse=True)
|
| 1368 |
+
|
| 1369 |
+
# Function to update typhoon dropdown when year changes
|
| 1370 |
+
def update_typhoons(year):
|
| 1371 |
+
if not year:
|
| 1372 |
+
return ["No typhoons available"]
|
| 1373 |
+
|
| 1374 |
+
typhoons = get_typhoons_for_year(int(year))
|
| 1375 |
if not typhoons:
|
| 1376 |
+
return ["No typhoons available for this year"]
|
| 1377 |
|
|
|
|
| 1378 |
return [name for name, _ in typhoons]
|
| 1379 |
|
| 1380 |
+
# Update typhoon dropdown when year changes
|
| 1381 |
year_dropdown.change(
|
| 1382 |
+
update_typhoons,
|
| 1383 |
inputs=year_dropdown,
|
| 1384 |
outputs=typhoon_dropdown
|
| 1385 |
)
|
| 1386 |
|
| 1387 |
+
# Add a "Generate" button
|
| 1388 |
+
generate_btn = gr.Button("Generate Typhoon Path")
|
| 1389 |
|
| 1390 |
+
# Display area for the typhoon animation
|
| 1391 |
+
path_plot = gr.Plot(label="Typhoon Path")
|
| 1392 |
|
| 1393 |
+
generate_btn.click(
|
| 1394 |
create_typhoon_path_animation,
|
| 1395 |
inputs=[year_dropdown, typhoon_dropdown, standard_dropdown],
|
| 1396 |
+
outputs=path_plot
|
| 1397 |
+
)
|
| 1398 |
+
|
| 1399 |
+
# Add a "Load Years" button
|
| 1400 |
+
gr.Button("Load Available Years").click(
|
| 1401 |
+
populate_years,
|
| 1402 |
+
inputs=None,
|
| 1403 |
+
outputs=year_dropdown
|
| 1404 |
)
|
| 1405 |
|
|
|
|
|
|
|
| 1406 |
# Run the app
|
| 1407 |
if __name__ == "__main__":
|
| 1408 |
# For Hugging Face, use a simpler version without threading
|