euler314 commited on
Commit
09a0f4d
·
verified ·
1 Parent(s): 912d5b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -12
app.py CHANGED
@@ -405,8 +405,14 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
405
  typhoon_search = gr.Textbox(label="Typhoon Search")
406
  analyze_btn = gr.Button("Generate Tracks")
407
  tracks_plot = gr.Plot(label="Typhoon Tracks")
 
 
 
 
 
 
408
  analyze_btn.click(
409
- fn=lambda *args: generate_main_analysis(*args)[0], # Only return the tracks plot
410
  inputs=[start_year, start_month, end_year, end_month, enso_phase, typhoon_search],
411
  outputs=tracks_plot
412
  )
@@ -422,8 +428,15 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
422
  wind_analyze_btn = gr.Button("Generate Wind Analysis")
423
  wind_scatter = gr.Plot(label="Wind Speed vs ONI")
424
  wind_regression_results = gr.Textbox(label="Wind Regression Results")
 
 
 
 
 
 
 
425
  wind_analyze_btn.click(
426
- fn=lambda *args: [generate_main_analysis(*args)[1], perform_wind_regression(args[0], args[1], args[2], args[3])],
427
  inputs=[wind_start_year, wind_start_month, wind_end_year, wind_end_month, wind_enso_phase, wind_typhoon_search],
428
  outputs=[wind_scatter, wind_regression_results]
429
  )
@@ -439,8 +452,15 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
439
  pressure_analyze_btn = gr.Button("Generate Pressure Analysis")
440
  pressure_scatter = gr.Plot(label="Pressure vs ONI")
441
  pressure_regression_results = gr.Textbox(label="Pressure Regression Results")
 
 
 
 
 
 
 
442
  pressure_analyze_btn.click(
443
- fn=lambda *args: [generate_main_analysis(*args)[2], perform_pressure_regression(args[0], args[1], args[2], args[3])],
444
  inputs=[pressure_start_year, pressure_start_month, pressure_end_year, pressure_end_month, pressure_enso_phase, pressure_typhoon_search],
445
  outputs=[pressure_scatter, pressure_regression_results]
446
  )
@@ -452,14 +472,21 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
452
  lon_end_year = gr.Number(label="End Year", value=2024, minimum=1900, maximum=2024, step=1)
453
  lon_end_month = gr.Dropdown(label="End Month", choices=list(range(1, 13)), value=6)
454
  lon_enso_phase = gr.Dropdown(label="ENSO Phase", choices=['all', 'El Nino', 'La Nina', 'Neutral'], value='all')
 
455
  lon_analyze_btn = gr.Button("Generate Longitude Analysis")
456
  regression_plot = gr.Plot(label="Longitude vs ONI")
457
  slopes_text = gr.Textbox(label="Regression Slopes")
458
  lon_regression_results = gr.Textbox(label="Longitude Regression Results")
 
 
 
 
 
 
 
459
  lon_analyze_btn.click(
460
- fn=lambda *args: [generate_main_analysis(*args)[3], generate_main_analysis(*args)[4],
461
- perform_longitude_regression(args[0], args[1], args[2], args[3])],
462
- inputs=[lon_start_year, lon_start_month, lon_end_year, lon_end_month, lon_enso_phase, ""],
463
  outputs=[regression_plot, slopes_text, lon_regression_results]
464
  )
465
 
@@ -470,8 +497,11 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
470
  standard_dropdown = gr.Dropdown(label="Classification Standard",
471
  choices=['atlantic', 'taiwan'], value='atlantic')
472
 
473
- # Fix the animation with modified function
474
  def generate_fixed_path_animation(year, typhoon, standard):
 
 
 
475
  typhoon_id = typhoon.split('(')[-1].strip(')')
476
  storm = ibtracs.get_storm(typhoon_id)
477
 
@@ -527,7 +557,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
527
  updatemenus=[{
528
  "buttons": [
529
  {
530
- "args": [None, {"frame": {"duration": 200, "redraw": True}, "fromcurrent": True}],
531
  "label": "Play",
532
  "method": "animate"
533
  },
@@ -545,6 +575,15 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
545
  }],
546
  sliders=[{
547
  "active": 0,
 
 
 
 
 
 
 
 
 
548
  "steps": [
549
  {
550
  "args": [[f.name], {
@@ -554,10 +593,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
554
  "label": str(i),
555
  "method": "animate"
556
  } for i, f in enumerate(frames)
557
- ],
558
- "x": 0.1,
559
- "y": 0,
560
- "len": 0.9
561
  }]
562
  )
563
 
@@ -571,6 +607,7 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
571
  2. Click "Generate Animation"
572
  3. Use the play button to start the animation
573
  4. Use the slider to scrub through different positions
 
574
  """)
575
 
576
  # Year dropdown change function
 
405
  typhoon_search = gr.Textbox(label="Typhoon Search")
406
  analyze_btn = gr.Button("Generate Tracks")
407
  tracks_plot = gr.Plot(label="Typhoon Tracks")
408
+
409
+ # Fixed function that extracts only the first return value
410
+ def get_tracks_plot(*args):
411
+ results = generate_main_analysis(*args)
412
+ return results[0]
413
+
414
  analyze_btn.click(
415
+ fn=get_tracks_plot,
416
  inputs=[start_year, start_month, end_year, end_month, enso_phase, typhoon_search],
417
  outputs=tracks_plot
418
  )
 
428
  wind_analyze_btn = gr.Button("Generate Wind Analysis")
429
  wind_scatter = gr.Plot(label="Wind Speed vs ONI")
430
  wind_regression_results = gr.Textbox(label="Wind Regression Results")
431
+
432
+ # Fixed function for wind analysis
433
+ def get_wind_analysis(start_year, start_month, end_year, end_month, enso_phase, typhoon_search):
434
+ results = generate_main_analysis(start_year, start_month, end_year, end_month, enso_phase, typhoon_search)
435
+ regression = perform_wind_regression(start_year, start_month, end_year, end_month)
436
+ return results[1], regression
437
+
438
  wind_analyze_btn.click(
439
+ fn=get_wind_analysis,
440
  inputs=[wind_start_year, wind_start_month, wind_end_year, wind_end_month, wind_enso_phase, wind_typhoon_search],
441
  outputs=[wind_scatter, wind_regression_results]
442
  )
 
452
  pressure_analyze_btn = gr.Button("Generate Pressure Analysis")
453
  pressure_scatter = gr.Plot(label="Pressure vs ONI")
454
  pressure_regression_results = gr.Textbox(label="Pressure Regression Results")
455
+
456
+ # Fixed function for pressure analysis
457
+ def get_pressure_analysis(start_year, start_month, end_year, end_month, enso_phase, typhoon_search):
458
+ results = generate_main_analysis(start_year, start_month, end_year, end_month, enso_phase, typhoon_search)
459
+ regression = perform_pressure_regression(start_year, start_month, end_year, end_month)
460
+ return results[2], regression
461
+
462
  pressure_analyze_btn.click(
463
+ fn=get_pressure_analysis,
464
  inputs=[pressure_start_year, pressure_start_month, pressure_end_year, pressure_end_month, pressure_enso_phase, pressure_typhoon_search],
465
  outputs=[pressure_scatter, pressure_regression_results]
466
  )
 
472
  lon_end_year = gr.Number(label="End Year", value=2024, minimum=1900, maximum=2024, step=1)
473
  lon_end_month = gr.Dropdown(label="End Month", choices=list(range(1, 13)), value=6)
474
  lon_enso_phase = gr.Dropdown(label="ENSO Phase", choices=['all', 'El Nino', 'La Nina', 'Neutral'], value='all')
475
+ lon_typhoon_search = gr.Textbox(label="Typhoon Search (Optional)")
476
  lon_analyze_btn = gr.Button("Generate Longitude Analysis")
477
  regression_plot = gr.Plot(label="Longitude vs ONI")
478
  slopes_text = gr.Textbox(label="Regression Slopes")
479
  lon_regression_results = gr.Textbox(label="Longitude Regression Results")
480
+
481
+ # Fixed function for longitude analysis
482
+ def get_longitude_analysis(start_year, start_month, end_year, end_month, enso_phase, typhoon_search):
483
+ results = generate_main_analysis(start_year, start_month, end_year, end_month, enso_phase, typhoon_search)
484
+ regression = perform_longitude_regression(start_year, start_month, end_year, end_month)
485
+ return results[3], results[4], regression
486
+
487
  lon_analyze_btn.click(
488
+ fn=get_longitude_analysis,
489
+ inputs=[lon_start_year, lon_start_month, lon_end_year, lon_end_month, lon_enso_phase, lon_typhoon_search],
 
490
  outputs=[regression_plot, slopes_text, lon_regression_results]
491
  )
492
 
 
497
  standard_dropdown = gr.Dropdown(label="Classification Standard",
498
  choices=['atlantic', 'taiwan'], value='atlantic')
499
 
500
+ # Fix the animation with improved function
501
  def generate_fixed_path_animation(year, typhoon, standard):
502
+ if not typhoon:
503
+ return None
504
+
505
  typhoon_id = typhoon.split('(')[-1].strip(')')
506
  storm = ibtracs.get_storm(typhoon_id)
507
 
 
557
  updatemenus=[{
558
  "buttons": [
559
  {
560
+ "args": [None, {"frame": {"duration": 200, "redraw": True}, "fromcurrent": True, "mode": "immediate"}],
561
  "label": "Play",
562
  "method": "animate"
563
  },
 
575
  }],
576
  sliders=[{
577
  "active": 0,
578
+ "yanchor": "top",
579
+ "xanchor": "left",
580
+ "currentvalue": {
581
+ "prefix": "Frame: "
582
+ },
583
+ "pad": {"b": 10, "t": 50},
584
+ "len": 0.9,
585
+ "x": 0.1,
586
+ "y": 0,
587
  "steps": [
588
  {
589
  "args": [[f.name], {
 
593
  "label": str(i),
594
  "method": "animate"
595
  } for i, f in enumerate(frames)
596
+ ]
 
 
 
597
  }]
598
  )
599
 
 
607
  2. Click "Generate Animation"
608
  3. Use the play button to start the animation
609
  4. Use the slider to scrub through different positions
610
+ 5. If animation doesn't play automatically, try using the slider to view frames
611
  """)
612
 
613
  # Year dropdown change function