Spaces:
Paused
Paused
Update inference.py
Browse files- inference.py +26 -26
inference.py
CHANGED
|
@@ -37,36 +37,36 @@ def process_document(file_path):
|
|
| 37 |
|
| 38 |
generated_ids = output[0][inputs.input_ids.shape[-1]:]
|
| 39 |
|
| 40 |
-
response = processor.decode( # past code
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
)
|
| 44 |
|
| 45 |
-
return response.strip()
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
# import json
|
| 71 |
# from model_loader import get_model
|
| 72 |
# from processor_utils import load_input
|
|
|
|
| 37 |
|
| 38 |
generated_ids = output[0][inputs.input_ids.shape[-1]:]
|
| 39 |
|
| 40 |
+
# response = processor.decode( # past code
|
| 41 |
+
# generated_ids,
|
| 42 |
+
# skip_special_tokens=True
|
| 43 |
+
# )
|
| 44 |
|
| 45 |
+
# return response.strip()
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
+
response = processor.decode(
|
| 50 |
+
generated_ids,
|
| 51 |
+
skip_special_tokens=True
|
| 52 |
+
).strip()
|
| 53 |
+
|
| 54 |
+
# 🔥 FORCE JSON CLEANING
|
| 55 |
+
start = response.find("{")
|
| 56 |
+
end = response.rfind("}") + 1
|
| 57 |
+
|
| 58 |
+
if start != -1 and end != -1:
|
| 59 |
+
response = response[start:end]
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
parsed = json.loads(response)
|
| 63 |
+
except:
|
| 64 |
+
parsed = {
|
| 65 |
+
"error": "Invalid JSON",
|
| 66 |
+
"raw": response
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return parsed
|
| 70 |
# import json
|
| 71 |
# from model_loader import get_model
|
| 72 |
# from processor_utils import load_input
|