jadechoghari
commited on
Commit
•
2efe921
1
Parent(s):
58040e9
Update inference.py
Browse files- inference.py +7 -4
inference.py
CHANGED
@@ -6,7 +6,7 @@ import re
|
|
6 |
import json
|
7 |
import subprocess
|
8 |
|
9 |
-
def process_inference_results(results):
|
10 |
"""
|
11 |
Process the inference results by:
|
12 |
1. Adding bounding boxes on the image based on the coordinates in 'text'.
|
@@ -34,9 +34,12 @@ def process_inference_results(results):
|
|
34 |
|
35 |
processed_images.append(img)
|
36 |
|
37 |
-
|
|
|
38 |
|
39 |
-
|
|
|
|
|
40 |
"""
|
41 |
Run the inference and capture the errors for debugging.
|
42 |
"""
|
@@ -85,7 +88,7 @@ def inference_and_run(image_path, prompt, conv_mode="ferret_llama_3", model_path
|
|
85 |
with open(output_file_path, "r") as output_file:
|
86 |
results = [json.loads(line) for line in output_file]
|
87 |
|
88 |
-
return process_inference_results(results)
|
89 |
else:
|
90 |
print("No output JSONL files found.")
|
91 |
return None, None
|
|
|
6 |
import json
|
7 |
import subprocess
|
8 |
|
9 |
+
def process_inference_results(results, process_image=False):
|
10 |
"""
|
11 |
Process the inference results by:
|
12 |
1. Adding bounding boxes on the image based on the coordinates in 'text'.
|
|
|
34 |
|
35 |
processed_images.append(img)
|
36 |
|
37 |
+
if process_image:
|
38 |
+
return processed_images, extracted_texts
|
39 |
|
40 |
+
return extracted_texts
|
41 |
+
|
42 |
+
def inference_and_run(image_path, prompt, conv_mode="ferret_llama_3", model_path="jadechoghari/Ferret-UI-Llama8b", box=None, process_image=False):
|
43 |
"""
|
44 |
Run the inference and capture the errors for debugging.
|
45 |
"""
|
|
|
88 |
with open(output_file_path, "r") as output_file:
|
89 |
results = [json.loads(line) for line in output_file]
|
90 |
|
91 |
+
return process_inference_results(results, process_image)
|
92 |
else:
|
93 |
print("No output JSONL files found.")
|
94 |
return None, None
|