linxy/LaTeX_OCR
Viewer • Updated • 269k • 1.26k • 175
How to use kingabzpro/t5gemma2-latex-ocr-1k with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="kingabzpro/t5gemma2-latex-ocr-1k") # Load model directly
from transformers import AutoProcessor, AutoModelForSeq2SeqLM
processor = AutoProcessor.from_pretrained("kingabzpro/t5gemma2-latex-ocr-1k")
model = AutoModelForSeq2SeqLM.from_pretrained("kingabzpro/t5gemma2-latex-ocr-1k")How to use kingabzpro/t5gemma2-latex-ocr-1k with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "kingabzpro/t5gemma2-latex-ocr-1k"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kingabzpro/t5gemma2-latex-ocr-1k",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/kingabzpro/t5gemma2-latex-ocr-1k
How to use kingabzpro/t5gemma2-latex-ocr-1k with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "kingabzpro/t5gemma2-latex-ocr-1k" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kingabzpro/t5gemma2-latex-ocr-1k",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "kingabzpro/t5gemma2-latex-ocr-1k" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kingabzpro/t5gemma2-latex-ocr-1k",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use kingabzpro/t5gemma2-latex-ocr-1k with Docker Model Runner:
docker model run hf.co/kingabzpro/t5gemma2-latex-ocr-1k
This model is a fine-tuned version of google/t5gemma-2-270m-270m on an unknown dataset.
from transformers import pipeline
generator = pipeline(
"image-text-to-text",
model="kingabzpro/t5gemma2-latex-ocr-1k",
)
generator(
val_ds[10]["image"],
text="<start_of_image> Convert this image to LaTeX. Output only LaTeX.",
generate_kwargs={"do_sample": False, "max_new_tokens": 100},
)
Output:
[{'input_text': '<start_of_image> Convert this image to LaTeX. Output only LaTeX.',
'generated_text': '<start_of_image> Convert this image to LaTeX. Output only LaTeX.f ( p , p ^ { \\prime } ) = \\ln \\left\\{ \\begin{array} { \\begin{array} { \\begin{array} { \\begin{array} { \\begin{array} { \\end{array} \\right\\} \\begin{array} { \\begin{array} { \\begin{array} { \\end{array} \\right\\} \\begin{array} { \\begin{array} { \\begin{array} {'}]
The following hyperparameters were used during training:
Base model
google/t5gemma-2-270m-270m