Update app.py
Browse files
app.py
CHANGED
|
@@ -276,8 +276,9 @@ def run_vlm_and_get_features(face_path: str, eye_path: str, prompt: Optional[str
|
|
| 276 |
(parsed_features_dict_or_None, raw_text_response_str)
|
| 277 |
|
| 278 |
We attempt to parse JSON as before, but always return the original raw text so it can be
|
| 279 |
-
forwarded verbatim to the LLM if desired. This function now
|
| 280 |
-
the
|
|
|
|
| 281 |
"""
|
| 282 |
prompt = prompt or DEFAULT_VLM_PROMPT
|
| 283 |
if not os.path.exists(face_path) or not os.path.exists(eye_path):
|
|
@@ -319,31 +320,29 @@ def run_vlm_and_get_features(face_path: str, eye_path: str, prompt: Optional[str
|
|
| 319 |
except Exception:
|
| 320 |
logger.info("VLM raw output (could not pretty print)")
|
| 321 |
|
| 322 |
-
# Try to parse JSON
|
| 323 |
parsed_features = None
|
| 324 |
try:
|
| 325 |
parsed_features = json.loads(text_out)
|
| 326 |
if not isinstance(parsed_features, dict):
|
| 327 |
parsed_features = None
|
| 328 |
except Exception:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
try:
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
parsed_features = json.loads(maybe)
|
| 336 |
-
if not isinstance(parsed_features, dict):
|
| 337 |
-
parsed_features = None
|
| 338 |
-
else:
|
| 339 |
-
parsed_features = None
|
| 340 |
-
except Exception:
|
| 341 |
parsed_features = None
|
| 342 |
|
| 343 |
# Log parsed features if available
|
| 344 |
if parsed_features is not None:
|
| 345 |
try:
|
| 346 |
-
logger.info("VLM parsed features:\n%s", json.dumps(parsed_features, indent=2, ensure_ascii=False))
|
| 347 |
except Exception:
|
| 348 |
logger.info("VLM parsed features (raw): %s", str(parsed_features))
|
| 349 |
else:
|
|
|
|
| 276 |
(parsed_features_dict_or_None, raw_text_response_str)
|
| 277 |
|
| 278 |
We attempt to parse JSON as before, but always return the original raw text so it can be
|
| 279 |
+
forwarded verbatim to the LLM if desired. This function now also tries the robust
|
| 280 |
+
regex extractor (extract_json_via_regex) on the raw text if json.loads fails, and logs
|
| 281 |
+
the extracted values.
|
| 282 |
"""
|
| 283 |
prompt = prompt or DEFAULT_VLM_PROMPT
|
| 284 |
if not os.path.exists(face_path) or not os.path.exists(eye_path):
|
|
|
|
| 320 |
except Exception:
|
| 321 |
logger.info("VLM raw output (could not pretty print)")
|
| 322 |
|
| 323 |
+
# Try to parse JSON first (as before)
|
| 324 |
parsed_features = None
|
| 325 |
try:
|
| 326 |
parsed_features = json.loads(text_out)
|
| 327 |
if not isinstance(parsed_features, dict):
|
| 328 |
parsed_features = None
|
| 329 |
except Exception:
|
| 330 |
+
parsed_features = None
|
| 331 |
+
|
| 332 |
+
# If json.loads failed, try regex-based extraction (robust)
|
| 333 |
+
if parsed_features is None:
|
| 334 |
try:
|
| 335 |
+
parsed_features = extract_json_via_regex(text_out)
|
| 336 |
+
logger.info("VLM regex-extracted features:\n%s", json.dumps(parsed_features, indent=2, ensure_ascii=False))
|
| 337 |
+
except Exception as e:
|
| 338 |
+
# No JSON-like block or extraction failed: keep parsed_features as None and log
|
| 339 |
+
logger.info("VLM regex extraction did not find structured JSON (this may be fine): %s", str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
parsed_features = None
|
| 341 |
|
| 342 |
# Log parsed features if available
|
| 343 |
if parsed_features is not None:
|
| 344 |
try:
|
| 345 |
+
logger.info("VLM parsed features (final):\n%s", json.dumps(parsed_features, indent=2, ensure_ascii=False))
|
| 346 |
except Exception:
|
| 347 |
logger.info("VLM parsed features (raw): %s", str(parsed_features))
|
| 348 |
else:
|