Add application file
Browse files
model.py
CHANGED
|
@@ -56,6 +56,10 @@ def extract_contact(image_path):
|
|
| 56 |
trimmed = generated[:, inputs.input_ids.shape[1]:]
|
| 57 |
result = processor.batch_decode(trimmed, skip_special_tokens=True)[0]
|
| 58 |
|
|
|
|
|
|
|
| 59 |
start = result.find("{")
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
| 56 |
trimmed = generated[:, inputs.input_ids.shape[1]:]
|
| 57 |
result = processor.batch_decode(trimmed, skip_special_tokens=True)[0]
|
| 58 |
|
| 59 |
+
# ponytail: raw_decode stops at the first complete object, ignoring any
|
| 60 |
+
# trailing text/repeated schema the model tacks on after the JSON
|
| 61 |
start = result.find("{")
|
| 62 |
+
if start == -1:
|
| 63 |
+
raise ValueError(f"no JSON in model output: {result!r}")
|
| 64 |
+
data, _ = json.JSONDecoder().raw_decode(result[start:])
|
| 65 |
+
return data
|