euler314 commited on
Commit
46eb885
·
verified ·
1 Parent(s): 26f3e96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -29
app.py CHANGED
@@ -1279,14 +1279,21 @@ def create_interface():
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
 
 
 
1289
  typhoon_dropdown = gr.Dropdown(
 
 
1290
  label="Typhoon",
1291
  interactive=True
1292
  )
@@ -1297,34 +1304,18 @@ def create_interface():
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
  # Update typhoon dropdown when year changes
1309
  def update_typhoon_dropdown(year):
1310
  if not year or ibtracs is None:
1311
- return [], None
1312
-
1313
  typhoons = get_typhoons_for_year(year)
1314
  if not typhoons:
1315
- return [], None
1316
-
1317
- # Return the choices and value directly
1318
- return [{"label": name, "value": id} for name, id in typhoons], typhoons[0][1] if typhoons else None
1319
-
1320
- # Update the year dropdown once at the beginning
1321
- demo.load(
1322
- update_year_dropdown,
1323
- inputs=None,
1324
- outputs=year_dropdown
1325
- )
1326
 
1327
- # Update typhoon dropdown when year changes
1328
  year_dropdown.change(
1329
  update_typhoon_dropdown,
1330
  inputs=year_dropdown,
@@ -1342,9 +1333,6 @@ def create_interface():
1342
  )
1343
 
1344
  return demo
1345
-
1346
-
1347
-
1348
 
1349
  # Run the app
1350
  if __name__ == "__main__":
@@ -1360,4 +1348,4 @@ if __name__ == "__main__":
1360
 
1361
  # Create and launch the Gradio interface
1362
  demo = create_interface()
1363
- demo.launch(share=True) # Use share=True for Hugging Face Spaces
 
1279
 
1280
  with gr.Tab("Typhoon Path Animation"):
1281
  with gr.Row():
1282
+ # Get initial years from ibtracs right away
1283
+ initial_years = sorted([year for year in range(1950, 2025) if ibtracs and year in ibtracs.data.keys()])
1284
+ initial_year = initial_years[-1] if initial_years else 2024
1285
+
1286
  year_dropdown = gr.Dropdown(
1287
+ choices=initial_years,
1288
+ value=initial_year,
1289
  label="Year"
1290
  )
1291
 
1292
+ # Initialize typhoons for the initial year
1293
+ initial_typhoons = get_typhoons_for_year(initial_year)
1294
  typhoon_dropdown = gr.Dropdown(
1295
+ choices=[name for name, _ in initial_typhoons],
1296
+ value=initial_typhoons[0][1] if initial_typhoons else None,
1297
  label="Typhoon",
1298
  interactive=True
1299
  )
 
1304
  label="Classification Standard"
1305
  )
1306
 
 
 
 
 
 
 
 
 
1307
  # Update typhoon dropdown when year changes
1308
  def update_typhoon_dropdown(year):
1309
  if not year or ibtracs is None:
1310
+ return []
1311
+
1312
  typhoons = get_typhoons_for_year(year)
1313
  if not typhoons:
1314
+ return []
1315
+
1316
+ # Return simple list for older Gradio versions
1317
+ return [name for name, _ in typhoons]
 
 
 
 
 
 
 
1318
 
 
1319
  year_dropdown.change(
1320
  update_typhoon_dropdown,
1321
  inputs=year_dropdown,
 
1333
  )
1334
 
1335
  return demo
 
 
 
1336
 
1337
  # Run the app
1338
  if __name__ == "__main__":
 
1348
 
1349
  # Create and launch the Gradio interface
1350
  demo = create_interface()
1351
+ demo.launch() # No parameters for Hugging Face Spaces