nakas commited on
Commit
ebff5fc
Β·
verified Β·
1 Parent(s): 8dc2e40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -45
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 with click-to-select functionality"""
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}<br><i>Click on map to change location</i>",
28
  icon=folium.Icon(color='red', icon='info-sign')
29
  ).add_to(m)
30
 
31
- # Add click functionality with JavaScript
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. **Click anywhere on the map** or enter coordinates for any US location
386
- 2. Click **"Get Weather Forecast"** for real-time NOAA data and UV analysis
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="Click on map or enter manually"
401
  )
402
  lon_input = gr.Number(
403
  label="πŸ“ Longitude",
404
  value=-98.5795,
405
  precision=4,
406
- info="Click on map or enter manually"
407
  )
408
 
409
  with gr.Row():
410
  update_btn = gr.Button("πŸ—ΊοΈ Update Location", variant="secondary", size="sm")
411
- weather_btn = gr.Button("🌀️ Get Weather Forecast", variant="primary", size="lg")
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 Weather Forecast'** to see detailed sunscreen recommendations based on current UV conditions.",
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