kjbytes commited on
Commit
cd27a30
·
1 Parent(s): e5d586b

Add application file

Browse files
Files changed (1) hide show
  1. model.py +6 -2
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
- end = result.rfind("}") + 1
61
- return json.loads(result[start:end])
 
 
 
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