Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
import torchvision
|
| 4 |
import base64
|
| 5 |
import fitz # PyMuPDF
|
| 6 |
import tempfile
|
| 7 |
from io import BytesIO
|
| 8 |
from PIL import Image
|
| 9 |
-
from transformers import AutoProcessor, AutoModelForVision2Seq
|
|
|
|
| 10 |
|
| 11 |
from olmocr.data.renderpdf import render_pdf_to_base64png
|
| 12 |
from olmocr.prompts.anchor import get_anchor_text
|
|
@@ -15,6 +16,16 @@ import re
|
|
| 15 |
import html
|
| 16 |
import json
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
#processor = AutoProcessor.from_pretrained("allenai/olmOCR-2-7B-1025-FP8")
|
| 19 |
#model = AutoModelForVision2Seq.from_pretrained("allenai/olmOCR-2-7B-1025-FP8",
|
| 20 |
# torch_dtype=torch.bfloat16,
|
|
@@ -22,10 +33,10 @@ import json
|
|
| 22 |
# low_cpu_mem_usage=True
|
| 23 |
# )
|
| 24 |
|
| 25 |
-
model = AutoModelForVision2Seq.from_pretrained("allenai/olmOCR-2-7B-1025-FP8", torch_dtype=torch.bfloat16).eval()
|
| 26 |
-
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
|
| 27 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 28 |
-
model.to(device)
|
| 29 |
|
| 30 |
|
| 31 |
#model = Qwen2VLForConditionalGeneration.from_pretrained(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
#import torchvision
|
| 4 |
import base64
|
| 5 |
import fitz # PyMuPDF
|
| 6 |
import tempfile
|
| 7 |
from io import BytesIO
|
| 8 |
from PIL import Image
|
| 9 |
+
#from transformers import AutoProcessor, AutoModelForVision2Seq
|
| 10 |
+
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
|
| 11 |
|
| 12 |
from olmocr.data.renderpdf import render_pdf_to_base64png
|
| 13 |
from olmocr.prompts.anchor import get_anchor_text
|
|
|
|
| 16 |
import html
|
| 17 |
import json
|
| 18 |
|
| 19 |
+
|
| 20 |
+
#from olmocr.data.renderpdf import render_pdf_to_base64png
|
| 21 |
+
#from olmocr.prompts import build_no_anchoring_v4_yaml_prompt
|
| 22 |
+
|
| 23 |
+
# Initialize the model
|
| 24 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained("allenai/olmOCR-2-7B-1025", torch_dtype=torch.bfloat16).eval()
|
| 25 |
+
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
|
| 26 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 27 |
+
model.to(device)
|
| 28 |
+
|
| 29 |
#processor = AutoProcessor.from_pretrained("allenai/olmOCR-2-7B-1025-FP8")
|
| 30 |
#model = AutoModelForVision2Seq.from_pretrained("allenai/olmOCR-2-7B-1025-FP8",
|
| 31 |
# torch_dtype=torch.bfloat16,
|
|
|
|
| 33 |
# low_cpu_mem_usage=True
|
| 34 |
# )
|
| 35 |
|
| 36 |
+
#model = AutoModelForVision2Seq.from_pretrained("allenai/olmOCR-2-7B-1025-FP8", torch_dtype=torch.bfloat16).eval()
|
| 37 |
+
#processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
|
| 38 |
+
#device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 39 |
+
#model.to(device)
|
| 40 |
|
| 41 |
|
| 42 |
#model = Qwen2VLForConditionalGeneration.from_pretrained(
|