Spaces:
Running
Running
Marc Allen Lopez commited on
Commit ·
778d70f
1
Parent(s): 5595512
Fix dots.ocr model error by switching to Qwen2-VL-2B-Instruct
Browse files- __pycache__/app.cpython-313.pyc +0 -0
- app.py +5 -5
- requirements.txt +0 -1
__pycache__/app.cpython-313.pyc
ADDED
|
Binary file (7.7 kB). View file
|
|
|
app.py
CHANGED
|
@@ -11,7 +11,7 @@ from transformers import AutoModelForCausalLM, AutoProcessor
|
|
| 11 |
from qwen_vl_utils import process_vision_info
|
| 12 |
|
| 13 |
|
| 14 |
-
MODEL_ID = os.getenv("OCR_MODEL_ID", "
|
| 15 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
|
| 17 |
# Use /tmp for model cache (always writable in containers)
|
|
@@ -39,7 +39,7 @@ def load_model():
|
|
| 39 |
|
| 40 |
processor, model = load_model()
|
| 41 |
|
| 42 |
-
app = FastAPI(title="TextSense OCR (
|
| 43 |
|
| 44 |
|
| 45 |
def read_image_from_upload(upload: UploadFile) -> Image.Image:
|
|
@@ -83,10 +83,10 @@ async def extract(
|
|
| 83 |
else:
|
| 84 |
return JSONResponse({"error": "No image provided. Provide 'image' file or 'image_url'."}, status_code=400)
|
| 85 |
|
| 86 |
-
# Prepare chat-style inputs for
|
| 87 |
prompt = (
|
| 88 |
-
"
|
| 89 |
-
"
|
| 90 |
)
|
| 91 |
messages = [
|
| 92 |
{
|
|
|
|
| 11 |
from qwen_vl_utils import process_vision_info
|
| 12 |
|
| 13 |
|
| 14 |
+
MODEL_ID = os.getenv("OCR_MODEL_ID", "Qwen/Qwen2-VL-2B-Instruct")
|
| 15 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
|
| 17 |
# Use /tmp for model cache (always writable in containers)
|
|
|
|
| 39 |
|
| 40 |
processor, model = load_model()
|
| 41 |
|
| 42 |
+
app = FastAPI(title="TextSense OCR (Qwen2-VL)")
|
| 43 |
|
| 44 |
|
| 45 |
def read_image_from_upload(upload: UploadFile) -> Image.Image:
|
|
|
|
| 83 |
else:
|
| 84 |
return JSONResponse({"error": "No image provided. Provide 'image' file or 'image_url'."}, status_code=400)
|
| 85 |
|
| 86 |
+
# Prepare chat-style inputs for Qwen2-VL
|
| 87 |
prompt = (
|
| 88 |
+
"Please extract all text from this image in natural reading order. "
|
| 89 |
+
"Provide only the extracted text without any additional commentary or formatting."
|
| 90 |
)
|
| 91 |
messages = [
|
| 92 |
{
|
requirements.txt
CHANGED
|
@@ -16,4 +16,3 @@ sentencepiece==0.2.0
|
|
| 16 |
safetensors==0.4.3
|
| 17 |
protobuf==3.20.3
|
| 18 |
qwen-vl-utils==0.0.8
|
| 19 |
-
flash-attn==2.6.3
|
|
|
|
| 16 |
safetensors==0.4.3
|
| 17 |
protobuf==3.20.3
|
| 18 |
qwen-vl-utils==0.0.8
|
|
|