Sanjayraju30 commited on
Commit
febf0a5
·
verified ·
1 Parent(s): 8d45176

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -9
app.py CHANGED
@@ -1,16 +1,75 @@
1
  import gradio as gr
 
2
  from weather_utils import get_weather_by_coordinates
3
 
4
- def on_map_click(latlon):
5
- lat, lon = latlon
6
- return get_weather_by_coordinates(lat, lon)
7
 
8
- with gr.Blocks() as app:
9
- gr.Markdown("## 🗺️ Hyderabad Weather Map\nClick anywhere in Hyderabad to see live weather ☁️🌧️☀️")
 
 
 
 
10
 
11
- map_input = gr.Map(label="Click anywhere on the map", value=(17.3850, 78.4867), zoom=11)
12
- output = gr.Markdown()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- map_input.change(fn=on_map_click, inputs=map_input, outputs=output)
 
 
 
 
 
 
15
 
16
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import plotly.graph_objects as go
3
  from weather_utils import get_weather_by_coordinates
4
 
5
+ # Hyderabad bounding box (lat/lon)
6
+ lat_range = [17.30, 17.55]
7
+ lon_range = [78.35, 78.60]
8
 
9
+ fig = go.Figure(go.Scattergeo(
10
+ lon = [],
11
+ lat = [],
12
+ mode = 'markers',
13
+ marker=dict(size=8, color='red'),
14
+ ))
15
 
16
+ fig.update_geos(
17
+ resolution=50,
18
+ scope='asia',
19
+ showcountries=False,
20
+ showsubunits=False,
21
+ lataxis_range=lat_range,
22
+ lonaxis_range=lon_range,
23
+ showland=True,
24
+ landcolor="lightgray",
25
+ fitbounds="locations"
26
+ )
27
+ fig.update_layout(
28
+ title="🗺️ Click anywhere on the map of Hyderabad",
29
+ geo=dict(bgcolor='white'),
30
+ margin={"r":0,"t":30,"l":0,"b":0},
31
+ )
32
 
33
+ def handle_click(trace, points, state):
34
+ if points.point_inds:
35
+ i = points.point_inds[0]
36
+ lat = points.lat[i]
37
+ lon = points.lon[i]
38
+ return get_weather_by_coordinates(lat, lon)
39
+ return "Please click on the map."
40
 
41
+ def simulate_click_map():
42
+ return fig
43
+
44
+ demo = gr.Interface(
45
+ fn=None,
46
+ inputs=[],
47
+ outputs=gr.Markdown(label="Weather Info"),
48
+ live=False,
49
+ title="🌦️ Hyderabad Weather Map",
50
+ description="Click on the map to get real-time weather",
51
+ )
52
+
53
+ demo = gr.Blocks()
54
+
55
+ with demo:
56
+ gr.Markdown("## 🌦️ Hyderabad Weather Forecast Map")
57
+ map_plot = gr.Plot(value=simulate_click_map)
58
+ coords = gr.Textbox(label="Latitude, Longitude (Click the map below)")
59
+ result = gr.Markdown()
60
+
61
+ def get_weather_from_click(latlon):
62
+ if not latlon:
63
+ return "No coordinates clicked"
64
+ lat, lon = map(float, latlon.split(","))
65
+ return get_weather_by_coordinates(lat, lon)
66
+
67
+ def update_coords(evt: gr.SelectData):
68
+ lat = evt.value["points"][0]["lat"]
69
+ lon = evt.value["points"][0]["lon"]
70
+ return f"{lat}, {lon}"
71
+
72
+ map_plot.select(update_coords, None, coords)
73
+ coords.change(get_weather_from_click, coords, result)
74
+
75
+ demo.launch()