Views
No views yet
Step3-VL-10B is now supported in llama-cpp-python. This project provides a test GGUF file.llama-cpp-python: https://github.com/JamePeng/llama-cpp-python1from llama_cpp import Llama
2from llama_cpp.llama_chat_format import Step3VLChatHandler
3import base64
4import os
5
6# Model and multimodal projection paths
7MODEL_PATH = r"path/to/Step3-VL-10B-Q8_0.gguf"
8MMPROJ_PATH = r"path/to/mmproj-Step3-VL-10b-F16.gguf"
9
10# Initialize the Llama model with vision support
11llm = Llama(
12 model_path=MODEL_PATH,
13 chat_handler=Step3VLChatHandler(
14 clip_model_path=MMPROJ_PATH,
15 enable_thinking=True, # Set to True if you want forced chain-of-thought output
16 verbose=True,
17 ),
18 n_gpu_layers=-1, # Use all available GPU layers
19 n_ctx=8192, # Context window size
20 verbose=True,
21)
22
23# Comprehensive MIME type mapping (updated as of 2025)
24# Based on Pillow 10.x+ "Fully Supported" (Read & Write) formats
25# Reference: IANA official media types + common real-world usage
26# See: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html
27_IMAGE_MIME_TYPES = {
28 # Most common formats
29 '.png': 'image/png',
30 '.jpg': 'image/jpeg',
31 '.jpeg': 'image/jpeg',
32 '.gif': 'image/gif',
33 '.webp': 'image/webp',
34
35 # Next-generation formats
36 '.avif': 'image/avif',
37 '.jp2': 'image/jp2',
38 '.j2k': 'image/jp2',
39 '.jpx': 'image/jp2',
40
41 # Legacy / Windows formats
42 '.bmp': 'image/bmp',
43 '.ico': 'image/x-icon',
44 '.pcx': 'image/x-pcx',
45 '.tga': 'image/x-tga',
46 '.icns': 'image/icns',
47
48 # Professional / Scientific imaging
49 '.tif': 'image/tiff',
50 '.tiff': 'image/tiff',
51 '.eps': 'application/postscript',
52 '.dds': 'image/vnd-ms.dds',
53 '.dib': 'image/dib',
54 '.sgi': 'image/sgi',
55
56 # Portable Map formats (PPM/PGM/PBM)
57 '.pbm': 'image/x-portable-bitmap',
58 '.pgm': 'image/x-portable-graymap',
59 '.ppm': 'image/x-portable-pixmap',
60
61 # Miscellaneous / Older formats
62 '.xbm': 'image/x-xbitmap',
63 '.mpo': 'image/mpo',
64 '.msp': 'image/msp',
65 '.im': 'image/x-pillow-im',
66 '.qoi': 'image/qoi',
67}
68
69def image_to_base64_data_uri(
70 file_path: str,
71 *,
72 fallback_mime: str = "application/octet-stream"
73) -> str:
74 """
75 Convert a local image file to a base64-encoded data URI with the correct MIME type.
76
77 Supports 20+ image formats (PNG, JPEG, WebP, AVIF, HEIC, SVG, BMP, ICO, TIFF, etc.).
78
79 Args:
80 file_path: Path to the image file on disk.
81 fallback_mime: MIME type used when the file extension is unknown.
82
83 Returns:
84 A valid data URI string (e.g., data:image/webp;base64,...).
85
86 Raises:
87 FileNotFoundError: If the file does not exist.
88 OSError: If reading the file fails.
89 """
90 if not os.path.isfile(file_path):
91 raise FileNotFoundError(f"Image file not found: {file_path}")
92
93 extension = os.path.splitext(file_path)[1].lower()
94 mime_type = _IMAGE_MIME_TYPES.get(extension, fallback_mime)
95
96 if mime_type == fallback_mime:
97 print(f"Warning: Unknown extension '{extension}' for '{file_path}'. "
98 f"Using fallback MIME type: {fallback_mime}")
99
100 try:
101 with open(file_path, "rb") as img_file:
102 encoded_data = base64.b64encode(img_file.read()).decode("utf-8")
103 except OSError as e:
104 raise OSError(f"Failed to read image file '{file_path}': {e}") from e
105
106 return f"data:{mime_type};base64,{encoded_data}"
107
108
109# ========================
110# Main image processing & inference section
111# ========================
112
113# 1. List of image paths you want to analyze (supports mixed formats)
114image_paths = [
115 r"6.jpeg",
116]
117
118# 2. Container for message content (each image + final text prompt)
119user_content = []
120
121# 3. Convert every image to a properly formatted data URI message
122for path in image_paths:
123 data_uri = image_to_base64_data_uri(path)
124 user_content.append({
125 "type": "image_url",
126 "image_url": {"url": data_uri}
127 })
128
129# 4. Append the text instruction (appears after all images in the message)
130user_content.append({
131 "type": "text",
132 "text": "Please describe this image." # You can change the prompt as needed
133})
134
135# 5. Perform chat completion with vision
136response = llm.create_chat_completion(
137 messages=[
138 # {"role": "system", "content": "You are a highly accurate vision-language assistant. Provide detailed, precise, and well-structured image descriptions."},
139 {"role": "user", "content": user_content}
140 ],
141 temperature=1.0,
142 top_p=0.95,
143 top_k=64,
144 max_tokens=8192,
145)
146
147# 6. Print the model's reply
148print(response["choices"][0]["message"]["content"])