Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from PIL import Image
|
|
| 17 |
from transformers import (
|
| 18 |
Qwen2VLForConditionalGeneration,
|
| 19 |
Qwen2_5_VLForConditionalGeneration,
|
|
|
|
| 20 |
AutoModelForImageTextToText,
|
| 21 |
AutoProcessor,
|
| 22 |
TextIteratorStreamer,
|
|
@@ -91,18 +92,16 @@ model_i = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
|
| 91 |
|
| 92 |
#-----------------------------------------#
|
| 93 |
|
| 94 |
-
# Load
|
| 95 |
-
MODEL_ID_J = "
|
| 96 |
-
SUBFOLDER = "Recognition"
|
| 97 |
processor_j = AutoProcessor.from_pretrained(
|
| 98 |
MODEL_ID_J,
|
| 99 |
trust_remote_code=True,
|
| 100 |
-
subfolder=SUBFOLDER
|
| 101 |
)
|
| 102 |
-
model_j =
|
| 103 |
MODEL_ID_J,
|
| 104 |
trust_remote_code=True,
|
| 105 |
-
|
| 106 |
torch_dtype=torch.float16
|
| 107 |
).to(device).eval()
|
| 108 |
#-----------------------------------------#
|
|
@@ -157,7 +156,7 @@ def process_document_stream(model_name: str, task_choice: str, image: Image.Imag
|
|
| 157 |
elif model_name == "Nanonets-OCR-s": processor, model = processor_c, model_c
|
| 158 |
elif model_name == "MonkeyOCR-Recognition": processor, model = processor_g, model_g
|
| 159 |
elif model_name == "olmOCR-7B-0725": processor, model = processor_i, model_i
|
| 160 |
-
elif model_name == "
|
| 161 |
else:
|
| 162 |
yield "Invalid model selected.", "Invalid model selected.", None
|
| 163 |
return
|
|
@@ -226,7 +225,7 @@ def create_gradio_interface():
|
|
| 226 |
"MonkeyOCR-Recognition",
|
| 227 |
"olmOCR-7B-0725",
|
| 228 |
"Nanonets-OCR-s",
|
| 229 |
-
"
|
| 230 |
"Megalodon-OCR-Sync-0713"
|
| 231 |
],
|
| 232 |
label="Select Model", value="Nanonets-OCR-s"
|
|
|
|
| 17 |
from transformers import (
|
| 18 |
Qwen2VLForConditionalGeneration,
|
| 19 |
Qwen2_5_VLForConditionalGeneration,
|
| 20 |
+
AutoModelForVision2Seq,
|
| 21 |
AutoModelForImageTextToText,
|
| 22 |
AutoProcessor,
|
| 23 |
TextIteratorStreamer,
|
|
|
|
| 92 |
|
| 93 |
#-----------------------------------------#
|
| 94 |
|
| 95 |
+
# Load NuExtract-2.0-4B
|
| 96 |
+
MODEL_ID_J = "numind/NuExtract-2.0-4B"
|
|
|
|
| 97 |
processor_j = AutoProcessor.from_pretrained(
|
| 98 |
MODEL_ID_J,
|
| 99 |
trust_remote_code=True,
|
|
|
|
| 100 |
)
|
| 101 |
+
model_j = AutoModelForVision2Seq.from_pretrained(
|
| 102 |
MODEL_ID_J,
|
| 103 |
trust_remote_code=True,
|
| 104 |
+
attn_implementation="flash_attention_2",
|
| 105 |
torch_dtype=torch.float16
|
| 106 |
).to(device).eval()
|
| 107 |
#-----------------------------------------#
|
|
|
|
| 156 |
elif model_name == "Nanonets-OCR-s": processor, model = processor_c, model_c
|
| 157 |
elif model_name == "MonkeyOCR-Recognition": processor, model = processor_g, model_g
|
| 158 |
elif model_name == "olmOCR-7B-0725": processor, model = processor_i, model_i
|
| 159 |
+
elif model_name == "NuExtract-2.0-4B": processor, model = processor_j, model_j
|
| 160 |
else:
|
| 161 |
yield "Invalid model selected.", "Invalid model selected.", None
|
| 162 |
return
|
|
|
|
| 225 |
"MonkeyOCR-Recognition",
|
| 226 |
"olmOCR-7B-0725",
|
| 227 |
"Nanonets-OCR-s",
|
| 228 |
+
"NuExtract-2.0-4B",
|
| 229 |
"Megalodon-OCR-Sync-0713"
|
| 230 |
],
|
| 231 |
label="Select Model", value="Nanonets-OCR-s"
|