Spaces:
Running
on
Zero
Running
on
Zero
hugohabicht01
commited on
Commit
·
5a467ab
1
Parent(s):
c790e67
make bbox parsing less strict
Browse files
app.py
CHANGED
@@ -201,7 +201,7 @@ def perform_anonymisation(input_image_pil: Image.Image, raw_model_output: str) -
|
|
201 |
print("Parsing findings...")
|
202 |
# Use the provided utility functions
|
203 |
parsed_findings = utils.parse_into_models(
|
204 |
-
utils.parse_json_response(raw_model_output)
|
205 |
)
|
206 |
print(f"[+] Parsed {len(parsed_findings)} findings.")
|
207 |
if not parsed_findings:
|
|
|
201 |
print("Parsing findings...")
|
202 |
# Use the provided utility functions
|
203 |
parsed_findings = utils.parse_into_models(
|
204 |
+
utils.parse_json_response(raw_model_output), strict=False
|
205 |
)
|
206 |
print(f"[+] Parsed {len(parsed_findings)} findings.")
|
207 |
if not parsed_findings:
|
utils.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from pydantic import BaseModel, field_validator
|
2 |
import numpy as np
|
3 |
import json
|
@@ -153,7 +154,7 @@ def parse_json_response(out: str) -> list[dict]:
|
|
153 |
return json.loads(fixed)
|
154 |
|
155 |
|
156 |
-
def parse_into_models(findings: list[dict]) -> list[Finding]:
|
157 |
"""Parses and validates a list of dictionaries into a list of Finding models.
|
158 |
|
159 |
Args:
|
@@ -162,6 +163,8 @@ def parse_into_models(findings: list[dict]) -> list[Finding]:
|
|
162 |
Returns:
|
163 |
A list of validated Finding model instances.
|
164 |
"""
|
|
|
|
|
165 |
return [Finding.model_validate(box) for box in findings]
|
166 |
|
167 |
|
|
|
1 |
+
from typing import Union
|
2 |
from pydantic import BaseModel, field_validator
|
3 |
import numpy as np
|
4 |
import json
|
|
|
154 |
return json.loads(fixed)
|
155 |
|
156 |
|
157 |
+
def parse_into_models(findings: list[dict], strict=True) -> Union[list[Finding], list[BoundingBox]]:
|
158 |
"""Parses and validates a list of dictionaries into a list of Finding models.
|
159 |
|
160 |
Args:
|
|
|
163 |
Returns:
|
164 |
A list of validated Finding model instances.
|
165 |
"""
|
166 |
+
if not strict:
|
167 |
+
return [BoundingBox.model_validate(box) for box in findings]
|
168 |
return [Finding.model_validate(box) for box in findings]
|
169 |
|
170 |
|