Update handler.py
Browse files- handler.py +12 -19
handler.py
CHANGED
|
@@ -57,27 +57,20 @@ class EndpointHandler:
|
|
| 57 |
|
| 58 |
# Define the prompt for Markdown conversion
|
| 59 |
prompt = "<image>\n<|grounding|>Convert the document to markdown."
|
| 60 |
-
|
| 61 |
-
# Run OCR inference
|
| 62 |
-
with tempfile.TemporaryDirectory() as temp_dir:
|
| 63 |
-
output_path = temp_dir # Now output_path is defined
|
| 64 |
-
|
| 65 |
-
# Define the prompt for Markdown conversion
|
| 66 |
-
prompt = "<image>\n<|grounding|>Convert the document to markdown."
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
except Exception as e:
|
| 83 |
print(f"Error processing image: {e}")
|
|
|
|
| 57 |
|
| 58 |
# Define the prompt for Markdown conversion
|
| 59 |
prompt = "<image>\n<|grounding|>Convert the document to markdown."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
# Run OCR inference
|
| 62 |
+
result = self.model.infer(
|
| 63 |
+
self.tokenizer,
|
| 64 |
+
prompt=prompt,
|
| 65 |
+
image_file=image,
|
| 66 |
+
output_path=None, # Use temporary directory
|
| 67 |
+
base_size=1024,
|
| 68 |
+
image_size=640,
|
| 69 |
+
crop_mode=True,
|
| 70 |
+
save_results=False # Save to temporary directory
|
| 71 |
+
)
|
| 72 |
|
| 73 |
+
return result
|
| 74 |
|
| 75 |
except Exception as e:
|
| 76 |
print(f"Error processing image: {e}")
|