Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,15 +13,13 @@ print("Loading model...")
|
|
| 13 |
model = AutoModel.from_pretrained(
|
| 14 |
model_name,
|
| 15 |
trust_remote_code=True,
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
).cuda().
|
| 19 |
|
| 20 |
def ocr_infer(image):
|
| 21 |
-
# Save temporary image
|
| 22 |
image.save("input.png")
|
| 23 |
|
| 24 |
-
# Standard OCR prompt
|
| 25 |
prompt = "<image>\nFree OCR."
|
| 26 |
|
| 27 |
result = model.infer(
|
|
@@ -29,20 +27,18 @@ def ocr_infer(image):
|
|
| 29 |
prompt=prompt,
|
| 30 |
image_file="input.png",
|
| 31 |
output_path=".",
|
| 32 |
-
base_size=1024,
|
| 33 |
image_size=640,
|
| 34 |
-
crop_mode=True
|
| 35 |
-
save_results=False
|
| 36 |
)
|
| 37 |
-
|
| 38 |
return result["text"]
|
| 39 |
|
| 40 |
demo = gr.Interface(
|
| 41 |
fn=ocr_infer,
|
| 42 |
inputs=gr.Image(type="pil"),
|
| 43 |
outputs="text",
|
| 44 |
-
title="DeepSeek-OCR
|
| 45 |
-
description="
|
| 46 |
)
|
| 47 |
|
| 48 |
demo.launch()
|
|
|
|
| 13 |
model = AutoModel.from_pretrained(
|
| 14 |
model_name,
|
| 15 |
trust_remote_code=True,
|
| 16 |
+
use_safetensors=True,
|
| 17 |
+
low_cpu_mem_usage=True
|
| 18 |
+
).cuda().eval()
|
| 19 |
|
| 20 |
def ocr_infer(image):
|
|
|
|
| 21 |
image.save("input.png")
|
| 22 |
|
|
|
|
| 23 |
prompt = "<image>\nFree OCR."
|
| 24 |
|
| 25 |
result = model.infer(
|
|
|
|
| 27 |
prompt=prompt,
|
| 28 |
image_file="input.png",
|
| 29 |
output_path=".",
|
|
|
|
| 30 |
image_size=640,
|
| 31 |
+
crop_mode=True
|
|
|
|
| 32 |
)
|
| 33 |
+
|
| 34 |
return result["text"]
|
| 35 |
|
| 36 |
demo = gr.Interface(
|
| 37 |
fn=ocr_infer,
|
| 38 |
inputs=gr.Image(type="pil"),
|
| 39 |
outputs="text",
|
| 40 |
+
title="DeepSeek-OCR (HF Space)",
|
| 41 |
+
description="GPU OCR API"
|
| 42 |
)
|
| 43 |
|
| 44 |
demo.launch()
|