Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -173,48 +173,73 @@ class OceanCurrentMapper:
|
|
173 |
wind_speeds = np.random.normal(10, 5, forecast_hours)
|
174 |
wind_speeds = np.maximum(wind_speeds, 0)
|
175 |
|
176 |
-
# Create
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
name='Wave Height (m)',
|
192 |
-
line=dict(color='green', width=2),
|
193 |
-
yaxis='y2'
|
194 |
-
))
|
195 |
-
|
196 |
-
fig.add_trace(go.Scatter(
|
197 |
-
x=times,
|
198 |
-
y=wind_speeds,
|
199 |
-
mode='lines+markers',
|
200 |
-
name='Wind Speed (m/s)',
|
201 |
-
line=dict(color='red', width=2),
|
202 |
-
yaxis='y3'
|
203 |
-
))
|
204 |
|
|
|
205 |
fig.update_layout(
|
206 |
title=f'Ocean Conditions Forecast - {region}',
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
yaxis3=dict(title='Wind Speed (m/s)', side='right', overlaying='y', position=0.95),
|
211 |
-
showlegend=True,
|
212 |
-
width=None, # Let it auto-size
|
213 |
-
height=350, # Smaller height for embedding
|
214 |
autosize=True,
|
215 |
margin=dict(l=50, r=50, t=80, b=50)
|
216 |
)
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
return fig
|
219 |
|
220 |
def analyze_surfing_conditions(self, region: str) -> str:
|
@@ -228,20 +253,20 @@ 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)
|
@@ -288,8 +313,8 @@ def analyze_conditions(region):
|
|
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: 3em; text-align: center; color: #
|
292 |
-
|
293 |
</h1>
|
294 |
|
295 |
<div style="text-align: center; font-size: 1.2em; margin-bottom: 2em;">
|
|
|
173 |
wind_speeds = np.random.normal(10, 5, forecast_hours)
|
174 |
wind_speeds = np.maximum(wind_speeds, 0)
|
175 |
|
176 |
+
# Create subplots for better separation
|
177 |
+
from plotly.subplots import make_subplots
|
178 |
+
|
179 |
+
fig = make_subplots(
|
180 |
+
rows=3, cols=1,
|
181 |
+
subplot_titles=('Current Speed (m/s)', 'Wave Height (m)', 'Wind Speed (m/s)'),
|
182 |
+
vertical_spacing=0.08,
|
183 |
+
shared_xaxes=True
|
184 |
+
)
|
185 |
+
|
186 |
+
# Current Speed subplot
|
187 |
+
fig.add_trace(
|
188 |
+
go.Scatter(
|
189 |
+
x=times,
|
190 |
+
y=current_speeds,
|
191 |
+
mode='lines+markers',
|
192 |
+
name='Current Speed',
|
193 |
+
line=dict(color='blue', width=2),
|
194 |
+
marker=dict(size=4)
|
195 |
+
),
|
196 |
+
row=1, col=1
|
197 |
+
)
|
198 |
+
|
199 |
+
# Wave Height subplot
|
200 |
+
fig.add_trace(
|
201 |
+
go.Scatter(
|
202 |
+
x=times,
|
203 |
+
y=wave_heights,
|
204 |
+
mode='lines+markers',
|
205 |
+
name='Wave Height',
|
206 |
+
line=dict(color='green', width=2),
|
207 |
+
marker=dict(size=4)
|
208 |
+
),
|
209 |
+
row=2, col=1
|
210 |
+
)
|
211 |
|
212 |
+
# Wind Speed subplot
|
213 |
+
fig.add_trace(
|
214 |
+
go.Scatter(
|
215 |
+
x=times,
|
216 |
+
y=wind_speeds,
|
217 |
+
mode='lines+markers',
|
218 |
+
name='Wind Speed',
|
219 |
+
line=dict(color='red', width=2),
|
220 |
+
marker=dict(size=4)
|
221 |
+
),
|
222 |
+
row=3, col=1
|
223 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
+
# Update layout
|
226 |
fig.update_layout(
|
227 |
title=f'Ocean Conditions Forecast - {region}',
|
228 |
+
showlegend=False, # Remove legend since subplot titles are clear
|
229 |
+
width=None,
|
230 |
+
height=600, # Increased height for 3 subplots
|
|
|
|
|
|
|
|
|
231 |
autosize=True,
|
232 |
margin=dict(l=50, r=50, t=80, b=50)
|
233 |
)
|
234 |
|
235 |
+
# Update x-axis labels
|
236 |
+
fig.update_xaxes(title_text="Time", row=3, col=1)
|
237 |
+
|
238 |
+
# Update y-axis labels
|
239 |
+
fig.update_yaxes(title_text="Speed (m/s)", row=1, col=1)
|
240 |
+
fig.update_yaxes(title_text="Height (m)", row=2, col=1)
|
241 |
+
fig.update_yaxes(title_text="Speed (m/s)", row=3, col=1)
|
242 |
+
|
243 |
return fig
|
244 |
|
245 |
def analyze_surfing_conditions(self, region: str) -> str:
|
|
|
253 |
conditions = []
|
254 |
|
255 |
if avg_speed < 0.3:
|
256 |
+
conditions.append("β
Low current speeds - good for beginners")
|
257 |
elif avg_speed < 0.8:
|
258 |
+
conditions.append("β οΈ Moderate currents - suitable for intermediate surfers")
|
259 |
else:
|
260 |
+
conditions.append("β Strong currents - experienced surfers only")
|
261 |
|
262 |
if max_speed > 1.0:
|
263 |
+
conditions.append("π Strong rip currents detected in some areas")
|
264 |
|
265 |
# Add mock weather conditions
|
266 |
conditions.extend([
|
267 |
+
f"π‘οΈ Water temperature: {20 + np.random.randint(0, 10)}Β°C",
|
268 |
+
f"π¨ Wind: {5 + np.random.randint(0, 15)} mph offshore",
|
269 |
+
f"π Wave height: {1 + np.random.randint(0, 3)} meters"
|
270 |
])
|
271 |
|
272 |
return "\n".join(conditions)
|
|
|
313 |
# Define the Gradio interface
|
314 |
with gr.Blocks(title="Ocean Current Mapper", theme=gr.themes.Ocean()) as demo:
|
315 |
gr.Markdown("""
|
316 |
+
<h1 style="font-size: 3em; text-align: center; color: #2E86AB; margin-bottom: 0.5em;">
|
317 |
+
π Real-Time Ocean Current Mapper
|
318 |
</h1>
|
319 |
|
320 |
<div style="text-align: center; font-size: 1.2em; margin-bottom: 2em;">
|