Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ import tempfile
|
|
| 15 |
import csv
|
| 16 |
from collections import defaultdict
|
| 17 |
import filecmp
|
|
|
|
| 18 |
|
| 19 |
# Command-line argument parsing
|
| 20 |
parser = argparse.ArgumentParser(description='Typhoon Analysis Dashboard')
|
|
@@ -293,7 +294,7 @@ def generate_main_analysis(start_year, start_month, end_year, end_month, enso_ph
|
|
| 293 |
|
| 294 |
return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
|
| 295 |
|
| 296 |
-
# Path animation function using Gallery
|
| 297 |
def categorize_typhoon_by_standard(wind_speed, standard):
|
| 298 |
if standard == 'taiwan':
|
| 299 |
wind_speed_ms = wind_speed * 0.514444
|
|
@@ -332,8 +333,11 @@ def generate_track_gallery(year, typhoon, standard):
|
|
| 332 |
lat_padding = max((max_lat - min_lat) * 0.3, 5)
|
| 333 |
lon_padding = max((max_lon - min_lon) * 0.3, 5)
|
| 334 |
|
| 335 |
-
#
|
|
|
|
| 336 |
gallery = []
|
|
|
|
|
|
|
| 337 |
for i in range(len(storm.time)):
|
| 338 |
fig = go.Figure()
|
| 339 |
|
|
@@ -386,7 +390,10 @@ def generate_track_gallery(year, typhoon, standard):
|
|
| 386 |
)
|
| 387 |
)
|
| 388 |
|
| 389 |
-
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
return gallery
|
| 392 |
|
|
@@ -641,4 +648,4 @@ with gr.Blocks(title="Typhoon Analysis Dashboard") as demo:
|
|
| 641 |
</style>
|
| 642 |
""")
|
| 643 |
|
| 644 |
-
demo.launch()
|
|
|
|
| 15 |
import csv
|
| 16 |
from collections import defaultdict
|
| 17 |
import filecmp
|
| 18 |
+
import uuid
|
| 19 |
|
| 20 |
# Command-line argument parsing
|
| 21 |
parser = argparse.ArgumentParser(description='Typhoon Analysis Dashboard')
|
|
|
|
| 294 |
|
| 295 |
return tracks_fig, wind_scatter, pressure_scatter, regression_fig, slopes_text
|
| 296 |
|
| 297 |
+
# Path animation function using Gallery with image export
|
| 298 |
def categorize_typhoon_by_standard(wind_speed, standard):
|
| 299 |
if standard == 'taiwan':
|
| 300 |
wind_speed_ms = wind_speed * 0.514444
|
|
|
|
| 333 |
lat_padding = max((max_lat - min_lat) * 0.3, 5)
|
| 334 |
lon_padding = max((max_lon - min_lon) * 0.3, 5)
|
| 335 |
|
| 336 |
+
# Temporary directory for images
|
| 337 |
+
temp_dir = tempfile.mkdtemp()
|
| 338 |
gallery = []
|
| 339 |
+
|
| 340 |
+
# Generate a sequence of figures and save as images
|
| 341 |
for i in range(len(storm.time)):
|
| 342 |
fig = go.Figure()
|
| 343 |
|
|
|
|
| 390 |
)
|
| 391 |
)
|
| 392 |
|
| 393 |
+
# Save figure as image
|
| 394 |
+
image_path = os.path.join(temp_dir, f"frame_{i}_{uuid.uuid4()}.png")
|
| 395 |
+
fig.write_image(image_path, width=1000, height=700)
|
| 396 |
+
gallery.append(image_path)
|
| 397 |
|
| 398 |
return gallery
|
| 399 |
|
|
|
|
| 648 |
</style>
|
| 649 |
""")
|
| 650 |
|
| 651 |
+
demo.launch(share=True) # Enable public link sharing
|