Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Upload 6 files
Browse files
app.py
CHANGED
|
@@ -221,7 +221,7 @@ def register_custom_routes(fastapi_app: FastAPI) -> None:
|
|
| 221 |
return JSONResponse(
|
| 222 |
{
|
| 223 |
"name": "Agentic Space Factory",
|
| 224 |
-
"version": "
|
| 225 |
"bucket_default": settings.bucket_name,
|
| 226 |
"workflows": ["build_from_model_card", "validate_existing_space", "runs_explorer"],
|
| 227 |
"custom_ui_status": "root_custom_ui",
|
|
@@ -395,12 +395,13 @@ def register_custom_routes(fastapi_app: FastAPI) -> None:
|
|
| 395 |
bucket_source = user_bucket_source(username=ctx["username"], bucket_name=bucket_name)
|
| 396 |
runs = list_recent_runs(bucket_source=bucket_source, token=ctx["token"], limit=limit)
|
| 397 |
resumable = find_latest_resumable_run(runs)
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
|
|
|
| 401 |
bundle = read_run_bundle(run_id, bucket_source=bucket_source, token=ctx["token"], include_heavy=False)
|
| 402 |
view = build_run_view_model(run_id, bundle, bucket_source=bucket_source)
|
| 403 |
-
return JSONResponse({"run":
|
| 404 |
|
| 405 |
@fastapi_app.get("/api/runs/{run_id}")
|
| 406 |
async def api_run_detail(request: Request, run_id: str, bucket_name: str = settings.bucket_name): # type: ignore[no-untyped-def]
|
|
@@ -519,10 +520,14 @@ def register_custom_routes(fastapi_app: FastAPI) -> None:
|
|
| 519 |
if job_stage and not job_info.get("error"):
|
| 520 |
effective_state["job_stage"] = job_stage
|
| 521 |
# Use Job stage as live source of truth while the bucket lags.
|
| 522 |
-
if job_stage in {"running", "
|
| 523 |
effective_state["status"] = job_stage
|
| 524 |
elif job_stage == "success" and not (bundle.get("events") or []):
|
| 525 |
effective_state["status"] = "success"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
events = _merge_events(bundle.get("events") or [], job_log_events)
|
| 527 |
progress = progress_from_events(events, state=effective_state)
|
| 528 |
view_bundle = {**bundle, "events": events}
|
|
|
|
| 221 |
return JSONResponse(
|
| 222 |
{
|
| 223 |
"name": "Agentic Space Factory",
|
| 224 |
+
"version": "v70-progress-resume-events-latency",
|
| 225 |
"bucket_default": settings.bucket_name,
|
| 226 |
"workflows": ["build_from_model_card", "validate_existing_space", "runs_explorer"],
|
| 227 |
"custom_ui_status": "root_custom_ui",
|
|
|
|
| 395 |
bucket_source = user_bucket_source(username=ctx["username"], bucket_name=bucket_name)
|
| 396 |
runs = list_recent_runs(bucket_source=bucket_source, token=ctx["token"], limit=limit)
|
| 397 |
resumable = find_latest_resumable_run(runs)
|
| 398 |
+
selected = resumable or (runs[0] if runs else None)
|
| 399 |
+
if not selected:
|
| 400 |
+
return JSONResponse({"run": None, "view": None, "bucket_source": bucket_source, "reason": "no_run"})
|
| 401 |
+
run_id = validate_run_id(str(selected.get("run_id")))
|
| 402 |
bundle = read_run_bundle(run_id, bucket_source=bucket_source, token=ctx["token"], include_heavy=False)
|
| 403 |
view = build_run_view_model(run_id, bundle, bucket_source=bucket_source)
|
| 404 |
+
return JSONResponse({"run": selected, "view": view, "bucket_source": bucket_source, "reason": "latest_resumable_run" if resumable else "latest_run"})
|
| 405 |
|
| 406 |
@fastapi_app.get("/api/runs/{run_id}")
|
| 407 |
async def api_run_detail(request: Request, run_id: str, bucket_name: str = settings.bucket_name): # type: ignore[no-untyped-def]
|
|
|
|
| 520 |
if job_stage and not job_info.get("error"):
|
| 521 |
effective_state["job_stage"] = job_stage
|
| 522 |
# Use Job stage as live source of truth while the bucket lags.
|
| 523 |
+
if job_stage in {"running", "cancelled"}:
|
| 524 |
effective_state["status"] = job_stage
|
| 525 |
elif job_stage == "success" and not (bundle.get("events") or []):
|
| 526 |
effective_state["status"] = "success"
|
| 527 |
+
# A failed HF Job stage is not always the final product state:
|
| 528 |
+
# some runs can still be in validation/repair/manual phases based on
|
| 529 |
+
# bucket events. Keep job_stage as metadata and let progress_from_events
|
| 530 |
+
# decide if the furthest observed step is truly failed.
|
| 531 |
events = _merge_events(bundle.get("events") or [], job_log_events)
|
| 532 |
progress = progress_from_events(events, state=effective_state)
|
| 533 |
view_bundle = {**bundle, "events": events}
|