Image-Text-to-Text
Transformers
Safetensors
English
ocr
vision
qwen2.5-vl
pdf
document-understanding
conversational
Instructions to use Thoughtseed/gutenocr-endpoint with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Thoughtseed/gutenocr-endpoint with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Thoughtseed/gutenocr-endpoint") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Thoughtseed/gutenocr-endpoint", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Thoughtseed/gutenocr-endpoint with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Thoughtseed/gutenocr-endpoint" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Thoughtseed/gutenocr-endpoint", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Thoughtseed/gutenocr-endpoint
- SGLang
How to use Thoughtseed/gutenocr-endpoint with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Thoughtseed/gutenocr-endpoint" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Thoughtseed/gutenocr-endpoint", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Thoughtseed/gutenocr-endpoint" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Thoughtseed/gutenocr-endpoint", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Thoughtseed/gutenocr-endpoint with Docker Model Runner:
docker model run hf.co/Thoughtseed/gutenocr-endpoint
pavun commited on
Commit ·
ae505d9
1
Parent(s): 34806df
Refactor EndpointHandler constructor to use model_dir parameter for consistency
Browse files- handler.py +6 -7
handler.py
CHANGED
|
@@ -1,25 +1,24 @@
|
|
| 1 |
import base64
|
| 2 |
import io
|
| 3 |
-
from PIL import Image
|
| 4 |
import torch
|
| 5 |
-
|
| 6 |
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 7 |
from qwen_vl_utils import process_vision_info
|
| 8 |
|
| 9 |
|
| 10 |
class EndpointHandler:
|
| 11 |
|
| 12 |
-
def __init__(self,
|
| 13 |
|
| 14 |
self.model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 15 |
-
|
| 16 |
torch_dtype=torch.bfloat16,
|
| 17 |
device_map="auto",
|
| 18 |
trust_remote_code=True
|
| 19 |
)
|
| 20 |
|
| 21 |
self.processor = AutoProcessor.from_pretrained(
|
| 22 |
-
|
| 23 |
trust_remote_code=True
|
| 24 |
)
|
| 25 |
|
|
@@ -53,7 +52,7 @@ class EndpointHandler:
|
|
| 53 |
images=image_inputs,
|
| 54 |
videos=video_inputs,
|
| 55 |
padding=True,
|
| 56 |
-
return_tensors="pt"
|
| 57 |
).to(self.model.device)
|
| 58 |
|
| 59 |
outputs = self.model.generate(**inputs, max_new_tokens=512)
|
|
@@ -68,4 +67,4 @@ class EndpointHandler:
|
|
| 68 |
skip_special_tokens=True
|
| 69 |
)
|
| 70 |
|
| 71 |
-
return decoded[0]
|
|
|
|
| 1 |
import base64
|
| 2 |
import io
|
|
|
|
| 3 |
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 6 |
from qwen_vl_utils import process_vision_info
|
| 7 |
|
| 8 |
|
| 9 |
class EndpointHandler:
|
| 10 |
|
| 11 |
+
def __init__(self, model_dir):
|
| 12 |
|
| 13 |
self.model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 14 |
+
model_dir,
|
| 15 |
torch_dtype=torch.bfloat16,
|
| 16 |
device_map="auto",
|
| 17 |
trust_remote_code=True
|
| 18 |
)
|
| 19 |
|
| 20 |
self.processor = AutoProcessor.from_pretrained(
|
| 21 |
+
model_dir,
|
| 22 |
trust_remote_code=True
|
| 23 |
)
|
| 24 |
|
|
|
|
| 52 |
images=image_inputs,
|
| 53 |
videos=video_inputs,
|
| 54 |
padding=True,
|
| 55 |
+
return_tensors="pt"
|
| 56 |
).to(self.model.device)
|
| 57 |
|
| 58 |
outputs = self.model.generate(**inputs, max_new_tokens=512)
|
|
|
|
| 67 |
skip_special_tokens=True
|
| 68 |
)
|
| 69 |
|
| 70 |
+
return {"result": decoded[0]}
|