Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Hunyuan-OCR-master/Hunyuan-OCR-vllm/run_hy_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from openai import OpenAI
from tqdm import tqdm
from typing import Dict, List
import mimetypes

def encode_image(image_path: str) -> str:
"""
Expand All @@ -28,16 +29,19 @@ def create_chat_messages(image_path: str, prompt: str) -> List[Dict]:
Returns:
List of message dictionaries
"""
# Detect MIME type (jpg/png/webp/etc)
mime, _ = mimetypes.guess_type(image_path)
if mime is None:
mime = "image/jpeg" # fallback

return [
{"role": "system", "content": ""},
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{encode_image(image_path)}"
}
"image_url": f"data:{mime};base64,{encode_image(image_path)}"
},
{"type": "text", "text": prompt}
]
Expand Down