Spaces:
Sleeping
Sleeping
Sync DemoService a96f1163494d7303146746e7a8b37f2f5c642b73
Browse files
api/ai-service/app/api/v1/endpoints/route_generation.py
CHANGED
|
@@ -656,8 +656,10 @@ def discover_shapes(payload: ShapeDiscoveryRequest) -> dict[str, Any]:
|
|
| 656 |
script_path = script_dir / "experimental_next_edge_service.py"
|
| 657 |
if str(script_dir) not in sys.path:
|
| 658 |
sys.path.insert(0, str(script_dir))
|
|
|
|
| 659 |
try:
|
| 660 |
module = _load_pipeline_module(script_dir / "clip_osm_region_test.py")
|
|
|
|
| 661 |
spec = importlib.util.spec_from_file_location("shape_discovery_runtime", script_path)
|
| 662 |
if spec is None or spec.loader is None:
|
| 663 |
raise RuntimeError("Shape discovery is unavailable")
|
|
@@ -666,6 +668,7 @@ def discover_shapes(payload: ShapeDiscoveryRequest) -> dict[str, Any]:
|
|
| 666 |
from gpx_outline_prefilter import load_prefilter
|
| 667 |
outlines = getattr(module, "GPX_SHAPE_TEMPLATES", {})
|
| 668 |
prefilter_path = workspace_dir / "data" / "models" / "gpx_outline_prefilter_experiment.pkl"
|
|
|
|
| 669 |
try:
|
| 670 |
prefilter_model = load_prefilter(str(prefilter_path))
|
| 671 |
outline_selection_mode = "learned_top_100_plus_geometric_12"
|
|
@@ -673,13 +676,16 @@ def discover_shapes(payload: ShapeDiscoveryRequest) -> dict[str, Any]:
|
|
| 673 |
logger.exception("GPX outline prefilter unavailable; using full search")
|
| 674 |
prefilter_model = None
|
| 675 |
outline_selection_mode = "full_fallback"
|
|
|
|
| 676 |
graph = experiment.fetch_small_walk_graph(payload.latitude, payload.longitude, radius_km=2.0)
|
|
|
|
| 677 |
road, paths_by_label, snap_distance = experiment.discover_shape_paths(
|
| 678 |
graph, {label: outlines.get(label, []) for label in ("dog", "symbol_star", "t_shirt")},
|
| 679 |
payload.latitude, payload.longitude, candidate_limit=None,
|
| 680 |
snap_limit=None, return_sources=True,
|
| 681 |
prefilter_model=prefilter_model, prefilter_limit=100,
|
| 682 |
)
|
|
|
|
| 683 |
ranker = None
|
| 684 |
ranker_runtime = None
|
| 685 |
if payload.rankWithGpxModel:
|
|
@@ -734,8 +740,10 @@ def discover_shapes(payload: ShapeDiscoveryRequest) -> dict[str, Any]:
|
|
| 734 |
except ValueError as exc:
|
| 735 |
raise HTTPException(status_code=422, detail=str(exc)) from exc
|
| 736 |
except Exception as exc:
|
| 737 |
-
logger.exception("shape discovery failed")
|
| 738 |
-
raise HTTPException(status_code=503, detail="์ด ์ง์ ์ ๋๋ก๋ฅผ ์กฐํํ์ง ๋ชปํ์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด ์ฃผ์ธ์."
|
|
|
|
|
|
|
| 739 |
|
| 740 |
|
| 741 |
def _nearby_road_return_routes(
|
|
|
|
| 656 |
script_path = script_dir / "experimental_next_edge_service.py"
|
| 657 |
if str(script_dir) not in sys.path:
|
| 658 |
sys.path.insert(0, str(script_dir))
|
| 659 |
+
stage = "load_pipeline"
|
| 660 |
try:
|
| 661 |
module = _load_pipeline_module(script_dir / "clip_osm_region_test.py")
|
| 662 |
+
stage = "load_discovery_runtime"
|
| 663 |
spec = importlib.util.spec_from_file_location("shape_discovery_runtime", script_path)
|
| 664 |
if spec is None or spec.loader is None:
|
| 665 |
raise RuntimeError("Shape discovery is unavailable")
|
|
|
|
| 668 |
from gpx_outline_prefilter import load_prefilter
|
| 669 |
outlines = getattr(module, "GPX_SHAPE_TEMPLATES", {})
|
| 670 |
prefilter_path = workspace_dir / "data" / "models" / "gpx_outline_prefilter_experiment.pkl"
|
| 671 |
+
stage = "load_prefilter"
|
| 672 |
try:
|
| 673 |
prefilter_model = load_prefilter(str(prefilter_path))
|
| 674 |
outline_selection_mode = "learned_top_100_plus_geometric_12"
|
|
|
|
| 676 |
logger.exception("GPX outline prefilter unavailable; using full search")
|
| 677 |
prefilter_model = None
|
| 678 |
outline_selection_mode = "full_fallback"
|
| 679 |
+
stage = "fetch_road_graph"
|
| 680 |
graph = experiment.fetch_small_walk_graph(payload.latitude, payload.longitude, radius_km=2.0)
|
| 681 |
+
stage = "route_outlines"
|
| 682 |
road, paths_by_label, snap_distance = experiment.discover_shape_paths(
|
| 683 |
graph, {label: outlines.get(label, []) for label in ("dog", "symbol_star", "t_shirt")},
|
| 684 |
payload.latitude, payload.longitude, candidate_limit=None,
|
| 685 |
snap_limit=None, return_sources=True,
|
| 686 |
prefilter_model=prefilter_model, prefilter_limit=100,
|
| 687 |
)
|
| 688 |
+
stage = "rank_routes"
|
| 689 |
ranker = None
|
| 690 |
ranker_runtime = None
|
| 691 |
if payload.rankWithGpxModel:
|
|
|
|
| 740 |
except ValueError as exc:
|
| 741 |
raise HTTPException(status_code=422, detail=str(exc)) from exc
|
| 742 |
except Exception as exc:
|
| 743 |
+
logger.exception("shape discovery failed at %s", stage)
|
| 744 |
+
raise HTTPException(status_code=503, detail="์ด ์ง์ ์ ๋๋ก๋ฅผ ์กฐํํ์ง ๋ชปํ์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด ์ฃผ์ธ์.",
|
| 745 |
+
headers={"X-Shape-Discovery-Stage": stage,
|
| 746 |
+
"X-Shape-Discovery-Error": type(exc).__name__}) from exc
|
| 747 |
|
| 748 |
|
| 749 |
def _nearby_road_return_routes(
|