Spaces:
Sleeping
Sleeping
Fix: fixed some bug for the new visualizers model
Browse files- app.py +1 -1
- core/visualizers.py +16 -13
- services/planner_service.py +2 -1
- ui/theme.py +1 -1
app.py
CHANGED
|
@@ -381,7 +381,7 @@ class LifeFlowAI:
|
|
| 381 |
def main():
|
| 382 |
app = LifeFlowAI()
|
| 383 |
demo = app.build_interface()
|
| 384 |
-
demo.launch(server_name="0.0.0.0", server_port=
|
| 385 |
#7860
|
| 386 |
if __name__ == "__main__":
|
| 387 |
main()
|
|
|
|
| 381 |
def main():
|
| 382 |
app = LifeFlowAI()
|
| 383 |
demo = app.build_interface()
|
| 384 |
+
demo.launch(server_name="0.0.0.0", server_port=8080, share=True, show_error=True)
|
| 385 |
#7860
|
| 386 |
if __name__ == "__main__":
|
| 387 |
main()
|
core/visualizers.py
CHANGED
|
@@ -136,7 +136,10 @@ def create_animated_map(structured_data=None):
|
|
| 136 |
"""
|
| 137 |
# 1. 初始化地圖 (預設台北)
|
| 138 |
center_lat, center_lon = 25.033, 121.565
|
| 139 |
-
m = folium.Map(location=[center_lat, center_lon], zoom_start=13, tiles="OpenStreetMap"
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
# 注入 CSS 樣式
|
| 142 |
m.get_root().html.add_child(folium.Element(CSS_STYLE))
|
|
@@ -174,7 +177,7 @@ def create_animated_map(structured_data=None):
|
|
| 174 |
]
|
| 175 |
|
| 176 |
# --- Layer 1: 路線 (Route) ---
|
| 177 |
-
route_group = folium.FeatureGroup(name="🚗
|
| 178 |
|
| 179 |
# 1.1 背景特效 (AntPath)
|
| 180 |
all_coords = []
|
|
@@ -209,8 +212,8 @@ def create_animated_map(structured_data=None):
|
|
| 209 |
subtitle=f"{from_n} ➔ {to_n}",
|
| 210 |
color="route",
|
| 211 |
metrics={
|
| 212 |
-
"
|
| 213 |
-
"
|
| 214 |
}
|
| 215 |
)
|
| 216 |
|
|
@@ -229,7 +232,7 @@ def create_animated_map(structured_data=None):
|
|
| 229 |
theme_idx = (idx + 1) % len(THEMES)
|
| 230 |
theme_color, theme_name = THEMES[theme_idx]
|
| 231 |
|
| 232 |
-
group_name = f"🔹
|
| 233 |
alt_group = folium.FeatureGroup(name=group_name, show=True)
|
| 234 |
|
| 235 |
chosen = task.get("chosen_poi", {})
|
|
@@ -257,8 +260,8 @@ def create_animated_map(structured_data=None):
|
|
| 257 |
subtitle=poi_name,
|
| 258 |
color="gray",
|
| 259 |
metrics={
|
| 260 |
-
"
|
| 261 |
-
"
|
| 262 |
},
|
| 263 |
is_alternative=True
|
| 264 |
)
|
|
@@ -267,13 +270,13 @@ def create_animated_map(structured_data=None):
|
|
| 267 |
location=[alat, alng], radius=7,
|
| 268 |
color=theme_color, fill=True, fill_color="white", fill_opacity=1,
|
| 269 |
popup=folium.Popup(popup_html, max_width=320),
|
| 270 |
-
tooltip=f"
|
| 271 |
).add_to(alt_group)
|
| 272 |
|
| 273 |
alt_group.add_to(m)
|
| 274 |
|
| 275 |
# --- Layer 3: 主要站點 (Main Stops) ---
|
| 276 |
-
stops_group = folium.FeatureGroup(name="📍
|
| 277 |
|
| 278 |
for i, stop in enumerate(timeline):
|
| 279 |
coords = stop.get("coordinates", {})
|
|
@@ -297,9 +300,9 @@ def create_animated_map(structured_data=None):
|
|
| 297 |
subtitle=loc_name,
|
| 298 |
color=theme_name,
|
| 299 |
metrics={
|
| 300 |
-
"
|
| 301 |
-
"
|
| 302 |
-
"
|
| 303 |
}
|
| 304 |
)
|
| 305 |
|
|
@@ -310,7 +313,7 @@ def create_animated_map(structured_data=None):
|
|
| 310 |
folium.Marker(
|
| 311 |
location=[lat, lng], icon=icon,
|
| 312 |
popup=folium.Popup(popup_html, max_width=320),
|
| 313 |
-
tooltip=f"
|
| 314 |
).add_to(stops_group)
|
| 315 |
|
| 316 |
stops_group.add_to(m)
|
|
|
|
| 136 |
"""
|
| 137 |
# 1. 初始化地圖 (預設台北)
|
| 138 |
center_lat, center_lon = 25.033, 121.565
|
| 139 |
+
m = folium.Map(location=[center_lat, center_lon], zoom_start=13, tiles="OpenStreetMap",
|
| 140 |
+
height=750, # 這裡!設定高度 (單位是像素 px,也可以用 "100%" 但在 Gradio 有時會無效)
|
| 141 |
+
width="100%"
|
| 142 |
+
)
|
| 143 |
|
| 144 |
# 注入 CSS 樣式
|
| 145 |
m.get_root().html.add_child(folium.Element(CSS_STYLE))
|
|
|
|
| 177 |
]
|
| 178 |
|
| 179 |
# --- Layer 1: 路線 (Route) ---
|
| 180 |
+
route_group = folium.FeatureGroup(name="🚗 Main Route", show=True)
|
| 181 |
|
| 182 |
# 1.1 背景特效 (AntPath)
|
| 183 |
all_coords = []
|
|
|
|
| 212 |
subtitle=f"{from_n} ➔ {to_n}",
|
| 213 |
color="route",
|
| 214 |
metrics={
|
| 215 |
+
"Duration": f"{dur} min",
|
| 216 |
+
"Distance": f"{dist / 1000:.1f} km"
|
| 217 |
}
|
| 218 |
)
|
| 219 |
|
|
|
|
| 232 |
theme_idx = (idx + 1) % len(THEMES)
|
| 233 |
theme_color, theme_name = THEMES[theme_idx]
|
| 234 |
|
| 235 |
+
group_name = f"🔹 Task {idx + 1} Alternatives ({theme_name.upper()})"
|
| 236 |
alt_group = folium.FeatureGroup(name=group_name, show=True)
|
| 237 |
|
| 238 |
chosen = task.get("chosen_poi", {})
|
|
|
|
| 260 |
subtitle=poi_name,
|
| 261 |
color="gray",
|
| 262 |
metrics={
|
| 263 |
+
"Extra duration": f"+{extra_min} min",
|
| 264 |
+
"Extra distance": f"+{extra_dist} m"
|
| 265 |
},
|
| 266 |
is_alternative=True
|
| 267 |
)
|
|
|
|
| 270 |
location=[alat, alng], radius=7,
|
| 271 |
color=theme_color, fill=True, fill_color="white", fill_opacity=1,
|
| 272 |
popup=folium.Popup(popup_html, max_width=320),
|
| 273 |
+
tooltip=f"Alternatives: {poi_name}"
|
| 274 |
).add_to(alt_group)
|
| 275 |
|
| 276 |
alt_group.add_to(m)
|
| 277 |
|
| 278 |
# --- Layer 3: 主要站點 (Main Stops) ---
|
| 279 |
+
stops_group = folium.FeatureGroup(name="📍 Main travel stops", show=True)
|
| 280 |
|
| 281 |
for i, stop in enumerate(timeline):
|
| 282 |
coords = stop.get("coordinates", {})
|
|
|
|
| 300 |
subtitle=loc_name,
|
| 301 |
color=theme_name,
|
| 302 |
metrics={
|
| 303 |
+
"Arrival time": stop.get("time", ""),
|
| 304 |
+
"Weather": stop.get("weather", ""),
|
| 305 |
+
"Air quality": stop.get("aqi", {}).get("label", "")
|
| 306 |
}
|
| 307 |
)
|
| 308 |
|
|
|
|
| 313 |
folium.Marker(
|
| 314 |
location=[lat, lng], icon=icon,
|
| 315 |
popup=folium.Popup(popup_html, max_width=320),
|
| 316 |
+
tooltip=f"Station {i + 1}: {loc_name}"
|
| 317 |
).add_to(stops_group)
|
| 318 |
|
| 319 |
stops_group.add_to(m)
|
services/planner_service.py
CHANGED
|
@@ -597,7 +597,8 @@ class PlannerService:
|
|
| 597 |
try:
|
| 598 |
session = self._get_live_session(session)
|
| 599 |
final_ref_id = poi_repo.get_last_id_by_session(session.session_id)
|
| 600 |
-
if not final_ref_id:
|
|
|
|
| 601 |
|
| 602 |
structured_data = poi_repo.load(final_ref_id)
|
| 603 |
|
|
|
|
| 597 |
try:
|
| 598 |
session = self._get_live_session(session)
|
| 599 |
final_ref_id = poi_repo.get_last_id_by_session(session.session_id)
|
| 600 |
+
if not final_ref_id:
|
| 601 |
+
raise ValueError(f"No results found")
|
| 602 |
|
| 603 |
structured_data = poi_repo.load(final_ref_id)
|
| 604 |
|
ui/theme.py
CHANGED
|
@@ -339,7 +339,7 @@ def get_enhanced_css() -> str:
|
|
| 339 |
.chat-input-row { padding: 12px !important; border-top: 1px solid #e2e8f0; background: white; align-items: center !important; }
|
| 340 |
|
| 341 |
.split-view-container { display: flex; gap: 24px; height: calc(100vh - 140px); min-height: 600px; }
|
| 342 |
-
.split-left-panel { flex: 1; overflow-y: auto; }
|
| 343 |
.split-right-panel { flex: 2; position: sticky; top: 100px; height: 100%; }
|
| 344 |
|
| 345 |
/* Animations */
|
|
|
|
| 339 |
.chat-input-row { padding: 12px !important; border-top: 1px solid #e2e8f0; background: white; align-items: center !important; }
|
| 340 |
|
| 341 |
.split-view-container { display: flex; gap: 24px; height: calc(100vh - 140px); min-height: 600px; }
|
| 342 |
+
.split-left-panel { flex: 1; position: sticky; overflow-y: auto; }
|
| 343 |
.split-right-panel { flex: 2; position: sticky; top: 100px; height: 100%; }
|
| 344 |
|
| 345 |
/* Animations */
|