Ritvik Shrivastava commited on
Commit Β·
fe386b4
1
Parent(s): a76bfb3
fix: separate @spaces.GPU from @app .api for ZeroGPU detection
Browse files
app.py
CHANGED
|
@@ -62,22 +62,18 @@ async def health():
|
|
| 62 |
|
| 63 |
|
| 64 |
# ββ Core inference API ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 65 |
-
|
| 66 |
-
@spaces.GPU
|
| 67 |
-
def
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
Accepts: image file + language preference
|
| 75 |
-
Returns: full JSON defect report
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
"""
|
| 80 |
-
# ββ Load image ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 81 |
try:
|
| 82 |
img_path = image_path.get("path") or image_path.get("url")
|
| 83 |
if img_path is None:
|
|
@@ -86,13 +82,8 @@ def analyze_defect(
|
|
| 86 |
except Exception as e:
|
| 87 |
return _error_response(f"Could not read image: {e}")
|
| 88 |
|
| 89 |
-
# ββ Run 3-step pipeline βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 90 |
try:
|
| 91 |
-
|
| 92 |
-
report = run_gharscan_pipeline(image, language=language, trace_session=session)
|
| 93 |
-
trace_logger.save_trace(session)
|
| 94 |
-
return report
|
| 95 |
-
|
| 96 |
except Exception as e:
|
| 97 |
return _error_response(f"Inference failed: {e}")
|
| 98 |
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
# ββ Core inference API ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 65 |
+
# ββ Core inference API ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 66 |
+
@spaces.GPU
|
| 67 |
+
def _gpu_inference(image: Image.Image, language: str) -> dict:
|
| 68 |
+
"""Standalone GPU function β must be at module level for ZeroGPU detection."""
|
| 69 |
+
session = trace_logger.start_trace()
|
| 70 |
+
report = run_gharscan_pipeline(image, language=language, trace_session=session)
|
| 71 |
+
trace_logger.save_trace(session)
|
| 72 |
+
return report
|
| 73 |
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
@app.api(name="analyze_defect")
|
| 76 |
+
def analyze_defect(image_path: dict, language: str = "en") -> dict:
|
|
|
|
|
|
|
| 77 |
try:
|
| 78 |
img_path = image_path.get("path") or image_path.get("url")
|
| 79 |
if img_path is None:
|
|
|
|
| 82 |
except Exception as e:
|
| 83 |
return _error_response(f"Could not read image: {e}")
|
| 84 |
|
|
|
|
| 85 |
try:
|
| 86 |
+
return _gpu_inference(image, language)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
return _error_response(f"Inference failed: {e}")
|
| 89 |
|