Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ class WeatherApp:
|
|
14 |
self.selected_lon = -98.5795
|
15 |
|
16 |
def create_map(self):
|
17 |
-
"""Create interactive folium map
|
18 |
m = folium.Map(
|
19 |
location=[self.selected_lat, self.selected_lon],
|
20 |
zoom_start=4,
|
@@ -24,42 +24,11 @@ class WeatherApp:
|
|
24 |
# Add a marker for the selected location
|
25 |
folium.Marker(
|
26 |
[self.selected_lat, self.selected_lon],
|
27 |
-
popup=f"Selected Location<br>Lat: {self.selected_lat:.4f}<br>Lon: {self.selected_lon:.4f}
|
28 |
icon=folium.Icon(color='red', icon='info-sign')
|
29 |
).add_to(m)
|
30 |
|
31 |
-
|
32 |
-
click_js = f"""
|
33 |
-
<script>
|
34 |
-
function onMapClick(e) {{
|
35 |
-
// Update the location inputs in Gradio
|
36 |
-
const lat = e.latlng.lat.toFixed(4);
|
37 |
-
const lon = e.latlng.lng.toFixed(4);
|
38 |
-
|
39 |
-
// Try to find and update the Gradio inputs
|
40 |
-
const latInput = document.querySelector('input[data-testid*="number-input"]');
|
41 |
-
const lonInputs = document.querySelectorAll('input[data-testid*="number-input"]');
|
42 |
-
|
43 |
-
if (latInput && lonInputs.length >= 2) {{
|
44 |
-
latInput.value = lat;
|
45 |
-
lonInputs[1].value = lon;
|
46 |
-
|
47 |
-
// Dispatch input events to trigger Gradio updates
|
48 |
-
latInput.dispatchEvent(new Event('input', {{ bubbles: true }}));
|
49 |
-
lonInputs[1].dispatchEvent(new Event('input', {{ bubbles: true }}));
|
50 |
-
}}
|
51 |
-
}}
|
52 |
-
|
53 |
-
// Wait for map to be ready then add click listener
|
54 |
-
setTimeout(function() {{
|
55 |
-
if (typeof window.map_{id(m)} !== 'undefined') {{
|
56 |
-
window.map_{id(m)}.on('click', onMapClick);
|
57 |
-
}}
|
58 |
-
}}, 1000);
|
59 |
-
</script>
|
60 |
-
"""
|
61 |
-
|
62 |
-
return m._repr_html_() + click_js
|
63 |
|
64 |
def update_location(self, lat, lon):
|
65 |
"""Update the selected location coordinates"""
|
@@ -293,19 +262,17 @@ class WeatherApp:
|
|
293 |
gridcolor='rgba(128,128,128,0.2)'
|
294 |
),
|
295 |
yaxis=dict(
|
296 |
-
title="Temperature (Β°F)",
|
297 |
side='left',
|
298 |
-
titlefont=dict(color='#FF6B6B'),
|
299 |
tickfont=dict(color='#FF6B6B'),
|
300 |
showgrid=True,
|
301 |
gridwidth=1,
|
302 |
gridcolor='rgba(255,107,107,0.2)'
|
303 |
),
|
304 |
yaxis2=dict(
|
305 |
-
title="UV Index",
|
306 |
overlaying='y',
|
307 |
side='right',
|
308 |
-
titlefont=dict(color='#4A90E2'),
|
309 |
tickfont=dict(color='#4A90E2'),
|
310 |
range=[0, max(12, max(uv_values) * 1.1)]
|
311 |
),
|
@@ -382,8 +349,8 @@ with gr.Blocks(title="NOAA Weather & UV Index Map", theme=gr.themes.Soft()) as d
|
|
382 |
**Interactive weather forecasting with professional-grade UV protection recommendations**
|
383 |
|
384 |
### π How to Use:
|
385 |
-
1. **
|
386 |
-
2. Click **"Get
|
387 |
3. View the interactive 24-hour forecast with temperature trends and UV index
|
388 |
4. Follow the science-based sunscreen recommendations below
|
389 |
|
@@ -397,18 +364,18 @@ with gr.Blocks(title="NOAA Weather & UV Index Map", theme=gr.themes.Soft()) as d
|
|
397 |
label="π Latitude",
|
398 |
value=39.8283,
|
399 |
precision=4,
|
400 |
-
info="
|
401 |
)
|
402 |
lon_input = gr.Number(
|
403 |
label="π Longitude",
|
404 |
value=-98.5795,
|
405 |
precision=4,
|
406 |
-
info="
|
407 |
)
|
408 |
|
409 |
with gr.Row():
|
410 |
update_btn = gr.Button("πΊοΈ Update Location", variant="secondary", size="sm")
|
411 |
-
weather_btn = gr.Button("
|
412 |
|
413 |
gr.Markdown("""
|
414 |
### π Popular Locations:
|
@@ -422,7 +389,6 @@ with gr.Blocks(title="NOAA Weather & UV Index Map", theme=gr.themes.Soft()) as d
|
|
422 |
|
423 |
with gr.Column(scale=2):
|
424 |
gr.Markdown("### πΊοΈ Interactive Map")
|
425 |
-
gr.Markdown("*Click anywhere on the map to select a new location*")
|
426 |
map_html = gr.HTML(
|
427 |
value=weather_app.create_map(),
|
428 |
label=""
|
@@ -441,7 +407,7 @@ with gr.Blocks(title="NOAA Weather & UV Index Map", theme=gr.themes.Soft()) as d
|
|
441 |
with gr.Column(scale=2):
|
442 |
gr.Markdown("### βοΈ UV Protection Recommendations")
|
443 |
recommendations = gr.Markdown(
|
444 |
-
value="Click **'Get
|
445 |
label=""
|
446 |
)
|
447 |
|
|
|
14 |
self.selected_lon = -98.5795
|
15 |
|
16 |
def create_map(self):
|
17 |
+
"""Create interactive folium map"""
|
18 |
m = folium.Map(
|
19 |
location=[self.selected_lat, self.selected_lon],
|
20 |
zoom_start=4,
|
|
|
24 |
# Add a marker for the selected location
|
25 |
folium.Marker(
|
26 |
[self.selected_lat, self.selected_lon],
|
27 |
+
popup=f"Selected Location<br>Lat: {self.selected_lat:.4f}<br>Lon: {self.selected_lon:.4f}",
|
28 |
icon=folium.Icon(color='red', icon='info-sign')
|
29 |
).add_to(m)
|
30 |
|
31 |
+
return m._repr_html_()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def update_location(self, lat, lon):
|
34 |
"""Update the selected location coordinates"""
|
|
|
262 |
gridcolor='rgba(128,128,128,0.2)'
|
263 |
),
|
264 |
yaxis=dict(
|
265 |
+
title=dict(text="Temperature (Β°F)", font=dict(color='#FF6B6B')),
|
266 |
side='left',
|
|
|
267 |
tickfont=dict(color='#FF6B6B'),
|
268 |
showgrid=True,
|
269 |
gridwidth=1,
|
270 |
gridcolor='rgba(255,107,107,0.2)'
|
271 |
),
|
272 |
yaxis2=dict(
|
273 |
+
title=dict(text="UV Index", font=dict(color='#4A90E2')),
|
274 |
overlaying='y',
|
275 |
side='right',
|
|
|
276 |
tickfont=dict(color='#4A90E2'),
|
277 |
range=[0, max(12, max(uv_values) * 1.1)]
|
278 |
),
|
|
|
349 |
**Interactive weather forecasting with professional-grade UV protection recommendations**
|
350 |
|
351 |
### π How to Use:
|
352 |
+
1. **Enter coordinates** for any US location or try the examples below
|
353 |
+
2. Click **"Get Sunscreen Report"** for real-time NOAA data and UV analysis
|
354 |
3. View the interactive 24-hour forecast with temperature trends and UV index
|
355 |
4. Follow the science-based sunscreen recommendations below
|
356 |
|
|
|
364 |
label="π Latitude",
|
365 |
value=39.8283,
|
366 |
precision=4,
|
367 |
+
info="Enter latitude or try examples below"
|
368 |
)
|
369 |
lon_input = gr.Number(
|
370 |
label="π Longitude",
|
371 |
value=-98.5795,
|
372 |
precision=4,
|
373 |
+
info="Enter longitude or try examples below"
|
374 |
)
|
375 |
|
376 |
with gr.Row():
|
377 |
update_btn = gr.Button("πΊοΈ Update Location", variant="secondary", size="sm")
|
378 |
+
weather_btn = gr.Button("π§΄ Get Sunscreen Report", variant="primary", size="lg")
|
379 |
|
380 |
gr.Markdown("""
|
381 |
### π Popular Locations:
|
|
|
389 |
|
390 |
with gr.Column(scale=2):
|
391 |
gr.Markdown("### πΊοΈ Interactive Map")
|
|
|
392 |
map_html = gr.HTML(
|
393 |
value=weather_app.create_map(),
|
394 |
label=""
|
|
|
407 |
with gr.Column(scale=2):
|
408 |
gr.Markdown("### βοΈ UV Protection Recommendations")
|
409 |
recommendations = gr.Markdown(
|
410 |
+
value="Click **'Get Sunscreen Report'** to see detailed UV protection recommendations based on current weather conditions.",
|
411 |
label=""
|
412 |
)
|
413 |
|