Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -633,82 +633,6 @@ def get_available_years():
|
|
633 |
|
634 |
# Function to get available typhoons for a selected year
|
635 |
# Function to get available typhoons for a selected year
|
636 |
-
def get_typhoons_for_year(year):
|
637 |
-
if not year or ibtracs is None:
|
638 |
-
return []
|
639 |
-
|
640 |
-
try:
|
641 |
-
year = int(year)
|
642 |
-
if year not in ibtracs.data:
|
643 |
-
return []
|
644 |
-
|
645 |
-
season = ibtracs.get_season(year)
|
646 |
-
storm_summary = season.summary()
|
647 |
-
|
648 |
-
typhoon_options = []
|
649 |
-
for i in range(storm_summary['season_storms']):
|
650 |
-
try:
|
651 |
-
storm_id = storm_summary['id'][i]
|
652 |
-
storm_name = storm_summary['name'][i]
|
653 |
-
# Use storm name as the display name, but return the ID as the value
|
654 |
-
display_name = f"{storm_name} ({storm_id})"
|
655 |
-
typhoon_options.append((display_name, storm_id))
|
656 |
-
except Exception as e:
|
657 |
-
print(f"Error retrieving typhoon info: {e}")
|
658 |
-
continue
|
659 |
-
|
660 |
-
return typhoon_options
|
661 |
-
except Exception as e:
|
662 |
-
print(f"Error getting typhoons for year {year}: {e}")
|
663 |
-
return []
|
664 |
-
|
665 |
-
# In the Gradio interface for the Typhoon Path Animation tab:
|
666 |
-
with gr.Tab("Typhoon Path Animation"):
|
667 |
-
with gr.Row():
|
668 |
-
available_years = [year for year in range(1950, 2025) if year in ibtracs.data.keys()] if ibtracs else []
|
669 |
-
year_dropdown = gr.Dropdown(
|
670 |
-
choices=available_years,
|
671 |
-
value=available_years[-1] if available_years else None,
|
672 |
-
label="Year"
|
673 |
-
)
|
674 |
-
|
675 |
-
typhoon_dropdown = gr.Dropdown(
|
676 |
-
label="Typhoon",
|
677 |
-
interactive=True
|
678 |
-
)
|
679 |
-
|
680 |
-
standard_dropdown = gr.Dropdown(
|
681 |
-
choices=["atlantic", "taiwan"],
|
682 |
-
value="atlantic",
|
683 |
-
label="Classification Standard"
|
684 |
-
)
|
685 |
-
|
686 |
-
# Update typhoon dropdown when year changes
|
687 |
-
def update_typhoon_dropdown(year):
|
688 |
-
if not year:
|
689 |
-
return [], None
|
690 |
-
|
691 |
-
typhoons = get_typhoons_for_year(year)
|
692 |
-
if not typhoons:
|
693 |
-
return [], None
|
694 |
-
|
695 |
-
return [{"label": name, "value": id} for name, id in typhoons], typhoons[0][1]
|
696 |
-
|
697 |
-
year_dropdown.change(
|
698 |
-
update_typhoon_dropdown,
|
699 |
-
inputs=year_dropdown,
|
700 |
-
outputs=[typhoon_dropdown, typhoon_dropdown]
|
701 |
-
)
|
702 |
-
|
703 |
-
animation_button = gr.Button("Generate Animation")
|
704 |
-
|
705 |
-
typhoon_animation = gr.Plot(label="Typhoon Path Animation")
|
706 |
-
|
707 |
-
animation_button.click(
|
708 |
-
create_typhoon_path_animation,
|
709 |
-
inputs=[year_dropdown, typhoon_dropdown, standard_dropdown],
|
710 |
-
outputs=typhoon_animation
|
711 |
-
)
|
712 |
|
713 |
# Create animation for typhoon path
|
714 |
def create_typhoon_path_animation(year, typhoon_id, standard):
|
@@ -1251,7 +1175,8 @@ def perform_logistic_regression(start_year, start_month, end_year, end_month, re
|
|
1251 |
# Define Gradio interface
|
1252 |
def create_interface():
|
1253 |
# Initialize data first
|
1254 |
-
|
|
|
1255 |
|
1256 |
# Define interface tabs
|
1257 |
with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
@@ -1354,9 +1279,10 @@ def create_interface():
|
|
1354 |
|
1355 |
with gr.Tab("Typhoon Path Animation"):
|
1356 |
with gr.Row():
|
|
|
1357 |
year_dropdown = gr.Dropdown(
|
1358 |
-
choices=[
|
1359 |
-
value=
|
1360 |
label="Year"
|
1361 |
)
|
1362 |
|
@@ -1371,14 +1297,36 @@ def create_interface():
|
|
1371 |
label="Classification Standard"
|
1372 |
)
|
1373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1374 |
# Update typhoon dropdown when year changes
|
1375 |
year_dropdown.change(
|
1376 |
-
|
1377 |
-
[{"label": name, "value": id} for name, id in get_typhoons_for_year(year)],
|
1378 |
-
get_typhoons_for_year(year)[0][1] if get_typhoons_for_year(year) else None
|
1379 |
-
),
|
1380 |
inputs=year_dropdown,
|
1381 |
-
outputs=
|
1382 |
)
|
1383 |
|
1384 |
animation_button = gr.Button("Generate Animation")
|
@@ -1392,6 +1340,9 @@ def create_interface():
|
|
1392 |
)
|
1393 |
|
1394 |
return demo
|
|
|
|
|
|
|
1395 |
|
1396 |
# Run the app
|
1397 |
if __name__ == "__main__":
|
|
|
633 |
|
634 |
# Function to get available typhoons for a selected year
|
635 |
# Function to get available typhoons for a selected year
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
636 |
|
637 |
# Create animation for typhoon path
|
638 |
def create_typhoon_path_animation(year, typhoon_id, standard):
|
|
|
1175 |
# Define Gradio interface
|
1176 |
def create_interface():
|
1177 |
# Initialize data first
|
1178 |
+
global oni_df, ibtracs, oni_data, typhoon_data, oni_long, typhoon_max, merged_data
|
1179 |
+
oni_df, ibtracs, typhoon_data = initialize_data()
|
1180 |
|
1181 |
# Define interface tabs
|
1182 |
with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
|
1279 |
|
1280 |
with gr.Tab("Typhoon Path Animation"):
|
1281 |
with gr.Row():
|
1282 |
+
# Initialize with placeholder years, we'll update it once loaded
|
1283 |
year_dropdown = gr.Dropdown(
|
1284 |
+
choices=[2020, 2021, 2022, 2023, 2024], # Placeholder until data is loaded
|
1285 |
+
value=2024,
|
1286 |
label="Year"
|
1287 |
)
|
1288 |
|
|
|
1297 |
label="Classification Standard"
|
1298 |
)
|
1299 |
|
1300 |
+
# Update the dropdowns with actual data once loaded
|
1301 |
+
def update_year_dropdown():
|
1302 |
+
if ibtracs is None:
|
1303 |
+
return [], None
|
1304 |
+
available_years = sorted([year for year in range(1950, 2025) if year in ibtracs.data.keys()])
|
1305 |
+
return gr.Dropdown.update(choices=available_years, value=available_years[-1] if available_years else None)
|
1306 |
+
|
1307 |
+
# Update typhoon dropdown when year changes
|
1308 |
+
def update_typhoon_dropdown(year):
|
1309 |
+
if not year or ibtracs is None:
|
1310 |
+
return gr.Dropdown.update(choices=[], value=None)
|
1311 |
+
|
1312 |
+
typhoons = get_typhoons_for_year(year)
|
1313 |
+
return gr.Dropdown.update(
|
1314 |
+
choices=[{"label": name, "value": id} for name, id in typhoons],
|
1315 |
+
value=typhoons[0][1] if typhoons else None
|
1316 |
+
)
|
1317 |
+
|
1318 |
+
# Update the year dropdown once at the beginning
|
1319 |
+
demo.load(
|
1320 |
+
update_year_dropdown,
|
1321 |
+
inputs=None,
|
1322 |
+
outputs=year_dropdown
|
1323 |
+
)
|
1324 |
+
|
1325 |
# Update typhoon dropdown when year changes
|
1326 |
year_dropdown.change(
|
1327 |
+
update_typhoon_dropdown,
|
|
|
|
|
|
|
1328 |
inputs=year_dropdown,
|
1329 |
+
outputs=typhoon_dropdown
|
1330 |
)
|
1331 |
|
1332 |
animation_button = gr.Button("Generate Animation")
|
|
|
1340 |
)
|
1341 |
|
1342 |
return demo
|
1343 |
+
|
1344 |
+
|
1345 |
+
|
1346 |
|
1347 |
# Run the app
|
1348 |
if __name__ == "__main__":
|