Update handler.py
Browse files- handler.py +7 -3
handler.py
CHANGED
|
@@ -88,12 +88,15 @@ class EndpointHandler:
|
|
| 88 |
except Exception as img_error:
|
| 89 |
return {"error": f"Invalid image: {str(img_error)}"}
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
# Run OCR inference
|
| 92 |
result = self.model.infer(
|
| 93 |
self.tokenizer,
|
| 94 |
prompt=prompt,
|
| 95 |
image_file=image_path, # Pass the PIL Image object directly
|
| 96 |
-
output_path=
|
| 97 |
base_size=1024,
|
| 98 |
image_size=640,
|
| 99 |
crop_mode=True,
|
|
@@ -101,9 +104,10 @@ class EndpointHandler:
|
|
| 101 |
eval_mode=True
|
| 102 |
)
|
| 103 |
|
| 104 |
-
for fname in os.listdir(
|
|
|
|
| 105 |
if fname.endswith(".md") or fname.endswith(".mmd"):
|
| 106 |
-
md_path = os.path.join(
|
| 107 |
with open(md_path, 'r', encoding='utf-8') as f:
|
| 108 |
markdown = f.read()
|
| 109 |
print("Markdown output:\n", markdown)
|
|
|
|
| 88 |
except Exception as img_error:
|
| 89 |
return {"error": f"Invalid image: {str(img_error)}"}
|
| 90 |
|
| 91 |
+
output_dir = os.path.join(temp_dir, "deepseek_out")
|
| 92 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 93 |
+
|
| 94 |
# Run OCR inference
|
| 95 |
result = self.model.infer(
|
| 96 |
self.tokenizer,
|
| 97 |
prompt=prompt,
|
| 98 |
image_file=image_path, # Pass the PIL Image object directly
|
| 99 |
+
output_path=output_dir,
|
| 100 |
base_size=1024,
|
| 101 |
image_size=640,
|
| 102 |
crop_mode=True,
|
|
|
|
| 104 |
eval_mode=True
|
| 105 |
)
|
| 106 |
|
| 107 |
+
for fname in os.listdir(output_dir):
|
| 108 |
+
print("File:\n", fname)
|
| 109 |
if fname.endswith(".md") or fname.endswith(".mmd"):
|
| 110 |
+
md_path = os.path.join(output_dir, fname)
|
| 111 |
with open(md_path, 'r', encoding='utf-8') as f:
|
| 112 |
markdown = f.read()
|
| 113 |
print("Markdown output:\n", markdown)
|