Spaces:
Sleeping
Sleeping
errors patch
Browse files
app.py
CHANGED
|
@@ -47,6 +47,14 @@ def generate_spatial_map(lat, lon, day_index, toggle_mode, loc_name="Target Loca
|
|
| 47 |
if lat == 0.0 and lon == 0.0:
|
| 48 |
return empty_map()
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# Creating a clean spread for a ~250-mile radius visualization
|
| 51 |
locations = [
|
| 52 |
{"name": loc_name, "lat": lat, "lon": lon},
|
|
@@ -63,28 +71,25 @@ def generate_spatial_map(lat, lon, day_index, toggle_mode, loc_name="Target Loca
|
|
| 63 |
aqua_drift = extract_drift(day_index)
|
| 64 |
aqua_temp = round(base_temp + aqua_drift)
|
| 65 |
|
| 66 |
-
# Apply strict color and text logic based on your toggle choice
|
| 67 |
if toggle_mode == "Historical (Grey)":
|
| 68 |
text_label = f"{base_temp}°F"
|
| 69 |
-
color = "#a1a1aa" # Grey
|
| 70 |
elif toggle_mode == "Aqua (Red)":
|
| 71 |
text_label = f"{aqua_temp}°F"
|
| 72 |
-
color = "#ef4444" # Red
|
| 73 |
else: # Both
|
| 74 |
text_label = f"{base_temp} / {aqua_temp}"
|
| 75 |
-
color = "#06b6d4" # Cyan (Easier to read on dark maps)
|
| 76 |
|
| 77 |
-
map_data.append({"lat": loc["lat"], "lon": loc["lon"], "text": text_label, "
|
| 78 |
|
| 79 |
df_map = pd.DataFrame(map_data)
|
| 80 |
|
|
|
|
| 81 |
fig = go.Figure(go.Scattermapbox(
|
| 82 |
lat=df_map['lat'],
|
| 83 |
lon=df_map['lon'],
|
| 84 |
mode='markers+text',
|
| 85 |
-
marker=dict(size=14, color=
|
| 86 |
text=df_map['text'],
|
| 87 |
-
textfont=dict(size=14, color=
|
| 88 |
textposition="top right",
|
| 89 |
hoverinfo='text',
|
| 90 |
hovertext=df_map['name']
|
|
@@ -154,7 +159,6 @@ custom_theme = gr.themes.Base(
|
|
| 154 |
input_background_fill="#0f172a",
|
| 155 |
)
|
| 156 |
|
| 157 |
-
# FIXED: Removed 'theme' from gr.Blocks() constructor per Gradio 6.0 rules
|
| 158 |
with gr.Blocks() as demo:
|
| 159 |
# Invisible states to track coordinates without breaking UI
|
| 160 |
lat_state = gr.State(0.0)
|
|
@@ -184,5 +188,4 @@ with gr.Blocks() as demo:
|
|
| 184 |
day_selector.change(fn=update_map, inputs=[lat_state, lon_state, day_selector, map_toggle], outputs=spatial_map)
|
| 185 |
map_toggle.change(fn=update_map, inputs=[lat_state, lon_state, day_selector, map_toggle], outputs=spatial_map)
|
| 186 |
|
| 187 |
-
# FIXED: Moved 'theme' parameter directly into the launch method
|
| 188 |
demo.launch(theme=custom_theme)
|
|
|
|
| 47 |
if lat == 0.0 and lon == 0.0:
|
| 48 |
return empty_map()
|
| 49 |
|
| 50 |
+
# Determine the universal color for the map view to prevent Plotly Series crashes
|
| 51 |
+
if toggle_mode == "Historical (Grey)":
|
| 52 |
+
map_color = "#a1a1aa" # Grey
|
| 53 |
+
elif toggle_mode == "Aqua (Red)":
|
| 54 |
+
map_color = "#ef4444" # Red
|
| 55 |
+
else: # Both
|
| 56 |
+
map_color = "#06b6d4" # Cyan
|
| 57 |
+
|
| 58 |
# Creating a clean spread for a ~250-mile radius visualization
|
| 59 |
locations = [
|
| 60 |
{"name": loc_name, "lat": lat, "lon": lon},
|
|
|
|
| 71 |
aqua_drift = extract_drift(day_index)
|
| 72 |
aqua_temp = round(base_temp + aqua_drift)
|
| 73 |
|
|
|
|
| 74 |
if toggle_mode == "Historical (Grey)":
|
| 75 |
text_label = f"{base_temp}°F"
|
|
|
|
| 76 |
elif toggle_mode == "Aqua (Red)":
|
| 77 |
text_label = f"{aqua_temp}°F"
|
|
|
|
| 78 |
else: # Both
|
| 79 |
text_label = f"{base_temp} / {aqua_temp}"
|
|
|
|
| 80 |
|
| 81 |
+
map_data.append({"lat": loc["lat"], "lon": loc["lon"], "text": text_label, "name": loc["name"]})
|
| 82 |
|
| 83 |
df_map = pd.DataFrame(map_data)
|
| 84 |
|
| 85 |
+
# Plotly generation using the single string map_color variable
|
| 86 |
fig = go.Figure(go.Scattermapbox(
|
| 87 |
lat=df_map['lat'],
|
| 88 |
lon=df_map['lon'],
|
| 89 |
mode='markers+text',
|
| 90 |
+
marker=dict(size=14, color=map_color, opacity=0.85),
|
| 91 |
text=df_map['text'],
|
| 92 |
+
textfont=dict(size=14, color=map_color, family="Arial Black"),
|
| 93 |
textposition="top right",
|
| 94 |
hoverinfo='text',
|
| 95 |
hovertext=df_map['name']
|
|
|
|
| 159 |
input_background_fill="#0f172a",
|
| 160 |
)
|
| 161 |
|
|
|
|
| 162 |
with gr.Blocks() as demo:
|
| 163 |
# Invisible states to track coordinates without breaking UI
|
| 164 |
lat_state = gr.State(0.0)
|
|
|
|
| 188 |
day_selector.change(fn=update_map, inputs=[lat_state, lon_state, day_selector, map_toggle], outputs=spatial_map)
|
| 189 |
map_toggle.change(fn=update_map, inputs=[lat_state, lon_state, day_selector, map_toggle], outputs=spatial_map)
|
| 190 |
|
|
|
|
| 191 |
demo.launch(theme=custom_theme)
|