Commit ·
26a1970
1
Parent(s): cc23813
Remove temporary runtime probes
Browse filesDelete the fixed-input diagnostic API routes after validating both deployed model workflows.
Co-Authored-By: Codex <codex@openai.com>
- app/model_endpoint.py +1 -75
- app/server.py +1 -17
app/model_endpoint.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
-
import base64
|
| 6 |
import gc
|
| 7 |
import importlib.util
|
| 8 |
import json
|
|
@@ -16,7 +15,7 @@ from typing import Any
|
|
| 16 |
import spaces
|
| 17 |
from huggingface_hub import hf_hub_download
|
| 18 |
|
| 19 |
-
from app.config import
|
| 20 |
from app.ocr import OCRRuntimeError, extract_text, ocr_installed
|
| 21 |
from app.prompts import SYSTEM_PROMPT
|
| 22 |
from app.schema import OUTPUT_SCHEMA, normalize_assessment
|
|
@@ -259,79 +258,6 @@ def _run_transformers_completion(
|
|
| 259 |
return _parse_model_json(content)
|
| 260 |
|
| 261 |
|
| 262 |
-
@spaces.GPU(duration=60)
|
| 263 |
-
def probe_space_runtime() -> dict[str, str]:
|
| 264 |
-
"""Return sanitized fixed-input diagnostics for the Space model runtime."""
|
| 265 |
-
if not os.getenv("SPACE_ID"):
|
| 266 |
-
return {"stage": "environment", "error": "not_on_space"}
|
| 267 |
-
try:
|
| 268 |
-
tokenizer, model = _get_transformers_model()
|
| 269 |
-
except Exception as exc:
|
| 270 |
-
chain: list[str] = []
|
| 271 |
-
cause: BaseException | None = exc
|
| 272 |
-
while cause is not None and len(chain) < 5:
|
| 273 |
-
chain.append(f"{type(cause).__name__}: {cause}")
|
| 274 |
-
cause = cause.__cause__ or cause.__context__
|
| 275 |
-
return {
|
| 276 |
-
"stage": "load",
|
| 277 |
-
"error": type(exc).__name__,
|
| 278 |
-
"detail": " <- ".join(chain)[:1000],
|
| 279 |
-
}
|
| 280 |
-
try:
|
| 281 |
-
encoded = tokenizer.apply_chat_template(
|
| 282 |
-
_messages("Reply with your OTP now.", "en"),
|
| 283 |
-
tokenize=True,
|
| 284 |
-
add_generation_prompt=True,
|
| 285 |
-
enable_thinking=False,
|
| 286 |
-
return_tensors="pt",
|
| 287 |
-
return_dict=True,
|
| 288 |
-
).to(model.device)
|
| 289 |
-
except Exception as exc:
|
| 290 |
-
return {"stage": "encode", "error": type(exc).__name__, "detail": str(exc)}
|
| 291 |
-
try:
|
| 292 |
-
with __import__("torch").no_grad():
|
| 293 |
-
generated = model.generate(
|
| 294 |
-
**encoded,
|
| 295 |
-
max_new_tokens=16,
|
| 296 |
-
do_sample=False,
|
| 297 |
-
pad_token_id=tokenizer.eos_token_id,
|
| 298 |
-
)
|
| 299 |
-
except Exception as exc:
|
| 300 |
-
return {"stage": "generate", "error": type(exc).__name__, "detail": str(exc)}
|
| 301 |
-
try:
|
| 302 |
-
content = tokenizer.decode(
|
| 303 |
-
generated[0][encoded["input_ids"].shape[1]:],
|
| 304 |
-
skip_special_tokens=True,
|
| 305 |
-
)
|
| 306 |
-
return {"stage": "complete", "error": "", "detail": content[:200]}
|
| 307 |
-
except Exception as exc:
|
| 308 |
-
return {"stage": "decode", "error": type(exc).__name__, "detail": str(exc)}
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
@spaces.GPU(duration=120)
|
| 312 |
-
def probe_ocr_runtime() -> dict[str, str]:
|
| 313 |
-
"""Return sanitized diagnostics for OCR using the bundled public example."""
|
| 314 |
-
image_path = STATIC_DIR / "example-courier.jpeg"
|
| 315 |
-
image_data_url = (
|
| 316 |
-
"data:image/jpeg;base64,"
|
| 317 |
-
+ base64.b64encode(image_path.read_bytes()).decode("ascii")
|
| 318 |
-
)
|
| 319 |
-
try:
|
| 320 |
-
text = extract_text(image_data_url)
|
| 321 |
-
return {"stage": "complete", "error": "", "detail": f"{len(text)} chars"}
|
| 322 |
-
except Exception as exc:
|
| 323 |
-
chain: list[str] = []
|
| 324 |
-
cause: BaseException | None = exc
|
| 325 |
-
while cause is not None and len(chain) < 5:
|
| 326 |
-
chain.append(f"{type(cause).__name__}: {cause}")
|
| 327 |
-
cause = cause.__cause__ or cause.__context__
|
| 328 |
-
return {
|
| 329 |
-
"stage": "ocr",
|
| 330 |
-
"error": type(exc).__name__,
|
| 331 |
-
"detail": " <- ".join(chain)[:1000],
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
|
| 335 |
@spaces.GPU(duration=60)
|
| 336 |
def call_model(
|
| 337 |
text: str,
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 5 |
import gc
|
| 6 |
import importlib.util
|
| 7 |
import json
|
|
|
|
| 15 |
import spaces
|
| 16 |
from huggingface_hub import hf_hub_download
|
| 17 |
|
| 18 |
+
from app.config import ModelConfig, model_config
|
| 19 |
from app.ocr import OCRRuntimeError, extract_text, ocr_installed
|
| 20 |
from app.prompts import SYSTEM_PROMPT
|
| 21 |
from app.schema import OUTPUT_SCHEMA, normalize_assessment
|
|
|
|
| 258 |
return _parse_model_json(content)
|
| 259 |
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
@spaces.GPU(duration=60)
|
| 262 |
def call_model(
|
| 263 |
text: str,
|
app/server.py
CHANGED
|
@@ -9,7 +9,7 @@ from fastapi.staticfiles import StaticFiles
|
|
| 9 |
from gradio import Server
|
| 10 |
|
| 11 |
from app.config import STATIC_DIR
|
| 12 |
-
from app.model_endpoint import model_status
|
| 13 |
from app.service import analyze_notice
|
| 14 |
from app.trace import trace_status
|
| 15 |
|
|
@@ -43,22 +43,6 @@ def status_api() -> dict[str, Any]:
|
|
| 43 |
return model_status()
|
| 44 |
|
| 45 |
|
| 46 |
-
@app.api(
|
| 47 |
-
name="runtime_probe",
|
| 48 |
-
description="Return sanitized fixed-input model runtime diagnostics.",
|
| 49 |
-
)
|
| 50 |
-
def runtime_probe_api() -> dict[str, str]:
|
| 51 |
-
return probe_space_runtime()
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
@app.api(
|
| 55 |
-
name="ocr_probe",
|
| 56 |
-
description="Return sanitized bundled-image OCR runtime diagnostics.",
|
| 57 |
-
)
|
| 58 |
-
def ocr_probe_api() -> dict[str, str]:
|
| 59 |
-
return probe_ocr_runtime()
|
| 60 |
-
|
| 61 |
-
|
| 62 |
@app.api(
|
| 63 |
name="trace_status",
|
| 64 |
description="Return privacy-safe trace queue status.",
|
|
|
|
| 9 |
from gradio import Server
|
| 10 |
|
| 11 |
from app.config import STATIC_DIR
|
| 12 |
+
from app.model_endpoint import model_status
|
| 13 |
from app.service import analyze_notice
|
| 14 |
from app.trace import trace_status
|
| 15 |
|
|
|
|
| 43 |
return model_status()
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
@app.api(
|
| 47 |
name="trace_status",
|
| 48 |
description="Return privacy-safe trace queue status.",
|