Spaces:
Sleeping
Sleeping
Update model reference to Qwen3.5-ocr-jp-2b
Browse files- Dockerfile +65 -0
- README.md +5 -5
- app.py +17 -10
Dockerfile
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Local-test Dockerfile for spaces/open_chandra_ocr.
|
| 2 |
+
#
|
| 3 |
+
# Mirrors the HF Space (ZeroGPU) stack so we can validate the inference path
|
| 4 |
+
# locally without the host's CUDA-13/Python-3.12 incompatibilities:
|
| 5 |
+
# - Ubuntu 22.04 ships Python 3.10 (= Space's Python)
|
| 6 |
+
# - cu12.4 runtime libs (pre-built torch 2.6.0 cu12 wheels target this)
|
| 7 |
+
# - causal_conv1d wheel for cu12torch2.6 / cp310 / cxx11abi=FALSE
|
| 8 |
+
#
|
| 9 |
+
# Build:
|
| 10 |
+
# docker build -t open-chandra-ocr-local spaces/open_chandra_ocr/
|
| 11 |
+
# Run:
|
| 12 |
+
# docker run --gpus all --rm -p 7860:7860 \
|
| 13 |
+
# -v $(pwd)/checkpoint/open-chandra-stage2-2b:/model:ro \
|
| 14 |
+
# -v $(pwd)/.cache/hf:/root/.cache/huggingface \
|
| 15 |
+
# open-chandra-ocr-local
|
| 16 |
+
# Open http://localhost:7860
|
| 17 |
+
|
| 18 |
+
FROM nvidia/cuda:12.4.1-devel-ubuntu22.04
|
| 19 |
+
|
| 20 |
+
# `devel` (not `runtime`) is required: triton JIT-compiles its CUDA driver
|
| 21 |
+
# bindings (`backends/nvidia/driver.c` → `cuda_utils.so`) at first invocation,
|
| 22 |
+
# which needs gcc + cuda.h. Without these the kernels silently fall back to CPU.
|
| 23 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 24 |
+
PYTHONUNBUFFERED=1 \
|
| 25 |
+
PIP_NO_CACHE_DIR=1 \
|
| 26 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1
|
| 27 |
+
|
| 28 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 29 |
+
python3.10 \
|
| 30 |
+
python3-pip \
|
| 31 |
+
python3.10-dev \
|
| 32 |
+
gcc \
|
| 33 |
+
g++ \
|
| 34 |
+
ca-certificates \
|
| 35 |
+
libgl1 \
|
| 36 |
+
libglib2.0-0 \
|
| 37 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 38 |
+
&& ln -sf /usr/bin/python3.10 /usr/bin/python
|
| 39 |
+
|
| 40 |
+
WORKDIR /app
|
| 41 |
+
|
| 42 |
+
# Pin torch+vision from the cu12.4 index so the wheel ABI matches our cuda image.
|
| 43 |
+
RUN pip install --no-cache-dir \
|
| 44 |
+
--extra-index-url https://download.pytorch.org/whl/cu124 \
|
| 45 |
+
torch==2.6.0 torchvision==0.21.0
|
| 46 |
+
|
| 47 |
+
COPY requirements.txt .
|
| 48 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 49 |
+
|
| 50 |
+
# Pre-install causal_conv1d for fla fast path (Python 3.10 / cu12 / torch 2.6 / cxx11abi=FALSE).
|
| 51 |
+
# app.py also tries to install at runtime; this pre-install just makes startup faster.
|
| 52 |
+
RUN pip install --no-cache-dir --no-deps \
|
| 53 |
+
https://github.com/Dao-AILab/causal-conv1d/releases/download/v1.5.0.post8/causal_conv1d-1.5.0.post8+cu12torch2.6cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
|
| 54 |
+
|
| 55 |
+
COPY app.py .
|
| 56 |
+
|
| 57 |
+
# Defaults: load model from the bind-mounted /model, expose Gradio on all interfaces.
|
| 58 |
+
ENV MODEL_ID=/model \
|
| 59 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 60 |
+
GRADIO_SERVER_PORT=7860 \
|
| 61 |
+
HF_HOME=/root/.cache/huggingface
|
| 62 |
+
|
| 63 |
+
EXPOSE 7860
|
| 64 |
+
|
| 65 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 📄
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: gray
|
|
@@ -10,18 +10,18 @@ pinned: false
|
|
| 10 |
license: apache-2.0
|
| 11 |
hardware: zero-a10g
|
| 12 |
models:
|
| 13 |
-
- ebinan92/
|
| 14 |
---
|
| 15 |
|
| 16 |
-
#
|
| 17 |
|
| 18 |
-
Gradio
|
| 19 |
|
| 20 |
## Configuration
|
| 21 |
|
| 22 |
Set these Space variables as needed:
|
| 23 |
|
| 24 |
-
- `MODEL_ID`: Hugging Face model repo or local model path. Defaults to `ebinan92/
|
| 25 |
- `HF_TOKEN`: required Space **Secret** for private models (read scope).
|
| 26 |
- `MAX_IMAGE_PIXELS`: area-based image cap (px²). Defaults to `2359296` (1536²) ≈ 2300 visual tokens — matches the [chandra-ocr-2 reference Space](https://huggingface.co/spaces/victor/chandra-ocr-2) for ZeroGPU-friendly latency.
|
| 27 |
- `PDF_DPI`: PDF render DPI. Defaults to `180`.
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Qwen3.5-OCR-JP-2B
|
| 3 |
emoji: 📄
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: gray
|
|
|
|
| 10 |
license: apache-2.0
|
| 11 |
hardware: zero-a10g
|
| 12 |
models:
|
| 13 |
+
- ebinan92/Qwen3.5-ocr-jp-2b
|
| 14 |
---
|
| 15 |
|
| 16 |
+
# Qwen3.5-OCR-JP-2B
|
| 17 |
|
| 18 |
+
Gradio demo for [`ebinan92/Qwen3.5-ocr-jp-2b`](https://huggingface.co/ebinan92/Qwen3.5-ocr-jp-2b) on Hugging Face Spaces.
|
| 19 |
|
| 20 |
## Configuration
|
| 21 |
|
| 22 |
Set these Space variables as needed:
|
| 23 |
|
| 24 |
+
- `MODEL_ID`: Hugging Face model repo or local model path. Defaults to `ebinan92/Qwen3.5-ocr-jp-2b`.
|
| 25 |
- `HF_TOKEN`: required Space **Secret** for private models (read scope).
|
| 26 |
- `MAX_IMAGE_PIXELS`: area-based image cap (px²). Defaults to `2359296` (1536²) ≈ 2300 visual tokens — matches the [chandra-ocr-2 reference Space](https://huggingface.co/spaces/victor/chandra-ocr-2) for ZeroGPU-friendly latency.
|
| 27 |
- `PDF_DPI`: PDF render DPI. Defaults to `180`.
|
app.py
CHANGED
|
@@ -12,26 +12,33 @@ import time
|
|
| 12 |
from pathlib import Path
|
| 13 |
|
| 14 |
# Pre-built causal_conv1d wheel (linear-attention dependency, can't compile in Space build).
|
| 15 |
-
# Pulled from Dao-AILab official GitHub release
|
|
|
|
|
|
|
|
|
|
| 16 |
_CAUSAL_CONV1D_WHEEL = (
|
| 17 |
"https://github.com/Dao-AILab/causal-conv1d/releases/download/v1.5.0.post8/"
|
| 18 |
-
"causal_conv1d-1.5.0.post8+cu12torch2.6cxx11abiFALSE-
|
|
|
|
| 19 |
)
|
| 20 |
try:
|
| 21 |
import causal_conv1d # noqa: F401
|
| 22 |
except ImportError:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
import gradio as gr
|
| 30 |
import spaces
|
| 31 |
from PIL import Image
|
| 32 |
|
| 33 |
|
| 34 |
-
MODEL_ID = os.getenv("MODEL_ID", "ebinan92/
|
| 35 |
PROMPT = os.getenv(
|
| 36 |
"OCR_PROMPT", "OCR this image as HTML layout blocks with bbox and label."
|
| 37 |
)
|
|
@@ -667,8 +674,8 @@ CSS = """
|
|
| 667 |
"""
|
| 668 |
|
| 669 |
|
| 670 |
-
with gr.Blocks(title="
|
| 671 |
-
gr.Markdown("#
|
| 672 |
gr.Markdown(
|
| 673 |
"Upload an image or PDF and run OCR. Predicted blocks are shown in the right pane.",
|
| 674 |
elem_classes=["app-sub"],
|
|
|
|
| 12 |
from pathlib import Path
|
| 13 |
|
| 14 |
# Pre-built causal_conv1d wheel (linear-attention dependency, can't compile in Space build).
|
| 15 |
+
# Pulled from Dao-AILab official GitHub release. Auto-selects the cpXY wheel matching the
|
| 16 |
+
# running Python version (HF Space = cp310, local dev py3.12 = cp312, etc.).
|
| 17 |
+
# Soft-fails on unsupported combos — flash-linear-attention falls back to its torch impl.
|
| 18 |
+
_CAUSAL_CONV1D_PY = f"cp{sys.version_info.major}{sys.version_info.minor}"
|
| 19 |
_CAUSAL_CONV1D_WHEEL = (
|
| 20 |
"https://github.com/Dao-AILab/causal-conv1d/releases/download/v1.5.0.post8/"
|
| 21 |
+
f"causal_conv1d-1.5.0.post8+cu12torch2.6cxx11abiFALSE-"
|
| 22 |
+
f"{_CAUSAL_CONV1D_PY}-{_CAUSAL_CONV1D_PY}-linux_x86_64.whl"
|
| 23 |
)
|
| 24 |
try:
|
| 25 |
import causal_conv1d # noqa: F401
|
| 26 |
except ImportError:
|
| 27 |
+
try:
|
| 28 |
+
subprocess.run(
|
| 29 |
+
[sys.executable, "-m", "pip", "install", _CAUSAL_CONV1D_WHEEL, "--no-deps", "-q"],
|
| 30 |
+
check=True,
|
| 31 |
+
)
|
| 32 |
+
import causal_conv1d # noqa: F401
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"[warn] causal_conv1d unavailable ({e}); slower linear-attention conv1d path will be used")
|
| 35 |
|
| 36 |
import gradio as gr
|
| 37 |
import spaces
|
| 38 |
from PIL import Image
|
| 39 |
|
| 40 |
|
| 41 |
+
MODEL_ID = os.getenv("MODEL_ID", "ebinan92/Qwen3.5-ocr-jp-2b")
|
| 42 |
PROMPT = os.getenv(
|
| 43 |
"OCR_PROMPT", "OCR this image as HTML layout blocks with bbox and label."
|
| 44 |
)
|
|
|
|
| 674 |
"""
|
| 675 |
|
| 676 |
|
| 677 |
+
with gr.Blocks(title="Qwen3.5-OCR-JP-2B", css=CSS) as demo:
|
| 678 |
+
gr.Markdown("# Qwen3.5-OCR-JP-2B", elem_classes=["app-title"])
|
| 679 |
gr.Markdown(
|
| 680 |
"Upload an image or PDF and run OCR. Predicted blocks are shown in the right pane.",
|
| 681 |
elem_classes=["app-sub"],
|