Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ import requests
|
|
8 |
import json
|
9 |
from typing import Dict, List, Tuple, Optional
|
10 |
import warnings
|
|
|
|
|
11 |
warnings.filterwarnings('ignore')
|
12 |
|
13 |
class OceanCurrentMapper:
|
@@ -226,42 +228,68 @@ class OceanCurrentMapper:
|
|
226 |
conditions = []
|
227 |
|
228 |
if avg_speed < 0.3:
|
229 |
-
conditions.append("
|
230 |
elif avg_speed < 0.8:
|
231 |
-
conditions.append("
|
232 |
else:
|
233 |
-
conditions.append("
|
234 |
|
235 |
if max_speed > 1.0:
|
236 |
-
conditions.append("
|
237 |
|
238 |
# Add mock weather conditions
|
239 |
conditions.extend([
|
240 |
-
f"
|
241 |
-
f"
|
242 |
-
f"
|
243 |
])
|
244 |
|
245 |
return "\n".join(conditions)
|
246 |
|
247 |
-
# Initialize the mapper
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
-
# Create
|
251 |
def create_current_map(region, resolution, show_vectors, show_speed, vector_scale):
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
def create_forecast(region, forecast_hours):
|
255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
|
257 |
def analyze_conditions(region):
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
# Define the Gradio interface
|
261 |
with gr.Blocks(title="Ocean Current Mapper", theme=gr.themes.Ocean()) as demo:
|
262 |
gr.Markdown("""
|
263 |
-
<h1 style="font-size:
|
264 |
-
|
265 |
</h1>
|
266 |
|
267 |
<div style="text-align: center; font-size: 1.2em; margin-bottom: 2em;">
|
@@ -388,11 +416,18 @@ with gr.Blocks(title="Ocean Current Mapper", theme=gr.themes.Ocean()) as demo:
|
|
388 |
**Note**: This demo uses synthetic data for demonstration. In production, it would connect to live oceanographic APIs.
|
389 |
""")
|
390 |
|
391 |
-
# Launch the app
|
392 |
if __name__ == "__main__":
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
import json
|
9 |
from typing import Dict, List, Tuple, Optional
|
10 |
import warnings
|
11 |
+
import time
|
12 |
+
import traceback
|
13 |
warnings.filterwarnings('ignore')
|
14 |
|
15 |
class OceanCurrentMapper:
|
|
|
228 |
conditions = []
|
229 |
|
230 |
if avg_speed < 0.3:
|
231 |
+
conditions.append("Low current speeds - good for beginners")
|
232 |
elif avg_speed < 0.8:
|
233 |
+
conditions.append("Moderate currents - suitable for intermediate surfers")
|
234 |
else:
|
235 |
+
conditions.append("Strong currents - experienced surfers only")
|
236 |
|
237 |
if max_speed > 1.0:
|
238 |
+
conditions.append("Strong rip currents detected in some areas")
|
239 |
|
240 |
# Add mock weather conditions
|
241 |
conditions.extend([
|
242 |
+
f"Water temperature: {20 + np.random.randint(0, 10)}Β°C",
|
243 |
+
f"Wind: {5 + np.random.randint(0, 15)} mph offshore",
|
244 |
+
f"Wave height: {1 + np.random.randint(0, 3)} meters"
|
245 |
])
|
246 |
|
247 |
return "\n".join(conditions)
|
248 |
|
249 |
+
# Initialize the mapper with error handling
|
250 |
+
try:
|
251 |
+
mapper = OceanCurrentMapper()
|
252 |
+
print("Ocean Current Mapper initialized successfully")
|
253 |
+
except Exception as e:
|
254 |
+
print(f"Error initializing mapper: {e}")
|
255 |
+
traceback.print_exc()
|
256 |
|
257 |
+
# Create wrapper functions with error handling
|
258 |
def create_current_map(region, resolution, show_vectors, show_speed, vector_scale):
|
259 |
+
try:
|
260 |
+
return mapper.create_current_map(region, resolution, show_vectors, show_speed, vector_scale)
|
261 |
+
except Exception as e:
|
262 |
+
print(f"Error creating current map: {e}")
|
263 |
+
traceback.print_exc()
|
264 |
+
# Return empty plot on error
|
265 |
+
fig = go.Figure()
|
266 |
+
fig.add_annotation(text=f"Error: {str(e)}", x=0.5, y=0.5, showarrow=False)
|
267 |
+
return fig
|
268 |
|
269 |
def create_forecast(region, forecast_hours):
|
270 |
+
try:
|
271 |
+
return mapper.get_forecast_data(region, forecast_hours)
|
272 |
+
except Exception as e:
|
273 |
+
print(f"Error creating forecast: {e}")
|
274 |
+
traceback.print_exc()
|
275 |
+
# Return empty plot on error
|
276 |
+
fig = go.Figure()
|
277 |
+
fig.add_annotation(text=f"Error: {str(e)}", x=0.5, y=0.5, showarrow=False)
|
278 |
+
return fig
|
279 |
|
280 |
def analyze_conditions(region):
|
281 |
+
try:
|
282 |
+
return mapper.analyze_surfing_conditions(region)
|
283 |
+
except Exception as e:
|
284 |
+
print(f"Error analyzing conditions: {e}")
|
285 |
+
traceback.print_exc()
|
286 |
+
return f"Error analyzing conditions: {str(e)}"
|
287 |
|
288 |
# Define the Gradio interface
|
289 |
with gr.Blocks(title="Ocean Current Mapper", theme=gr.themes.Ocean()) as demo:
|
290 |
gr.Markdown("""
|
291 |
+
<h1 style="font-size: 4em; text-align: center; color: #1e3a8a; text-shadow: 2px 2px 4px rgba(0,0,0,0.3); font-family: 'Arial Black', sans-serif;">
|
292 |
+
Real-Time Ocean Current Mapping Tool
|
293 |
</h1>
|
294 |
|
295 |
<div style="text-align: center; font-size: 1.2em; margin-bottom: 2em;">
|
|
|
416 |
**Note**: This demo uses synthetic data for demonstration. In production, it would connect to live oceanographic APIs.
|
417 |
""")
|
418 |
|
419 |
+
# Launch the app with better error handling
|
420 |
if __name__ == "__main__":
|
421 |
+
try:
|
422 |
+
print("Starting Ocean Current Mapper...")
|
423 |
+
demo.launch(
|
424 |
+
share=True,
|
425 |
+
height=600,
|
426 |
+
show_error=True,
|
427 |
+
inbrowser=False,
|
428 |
+
server_name="0.0.0.0",
|
429 |
+
server_port=7860
|
430 |
+
)
|
431 |
+
except Exception as e:
|
432 |
+
print(f"Error launching app: {e}")
|
433 |
+
traceback.print_exc()
|