Update README.md
Browse files
README.md
CHANGED
@@ -205,49 +205,42 @@ print(processor.decode(out[0].split("<answer>")[1].split("</answer>")[0], skip_s
|
|
205 |
|
206 |
|
207 |
## vLLM:
|
208 |
-
```
|
209 |
-
|
210 |
-
|
211 |
-
from transformers import AutoProcessor
|
212 |
-
|
213 |
-
model_id = "Numind/NuMarkdown-reasoning"
|
214 |
-
|
215 |
-
llm = LLM(
|
216 |
-
model=model_id,
|
217 |
-
tokenizer=model_id,
|
218 |
-
dtype="bfloat16",
|
219 |
-
gpu_memory_utilization=0.85,
|
220 |
-
max_num_seqs=256,
|
221 |
-
enforce_eager=True,
|
222 |
-
trust_remote_code=True
|
223 |
-
)
|
224 |
-
|
225 |
-
sampling_params = SamplingParams(
|
226 |
-
temperature=0.8,
|
227 |
-
max_tokens=5000,
|
228 |
-
)
|
229 |
-
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
{"type": "image"},
|
236 |
-
]
|
237 |
-
}]
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
tokenize=False,
|
242 |
-
add_generation_prompt=True,
|
243 |
-
)
|
244 |
-
image = Image.open("invoice.png").convert("RGB")
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
|
251 |
-
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
```
|
|
|
205 |
|
206 |
|
207 |
## vLLM:
|
208 |
+
```
|
209 |
+
vllm serve numind/NuMarkdown-reasoning --trust_remote_code --limit-mm-per-prompt image=1
|
210 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
+
```python
|
213 |
+
import json
|
214 |
+
from openai import OpenAI
|
215 |
+
import base64
|
|
|
|
|
|
|
216 |
|
217 |
+
openai_api_key = "EMPTY"
|
218 |
+
openai_api_base = "http://localhost:8000/v1"
|
|
|
|
|
|
|
|
|
219 |
|
220 |
+
client = OpenAI(
|
221 |
+
api_key=openai_api_key,
|
222 |
+
base_url=openai_api_base,
|
223 |
+
)
|
224 |
|
225 |
+
def encode_image(image_path):
|
226 |
+
"""
|
227 |
+
Encode the image file to base64 string
|
228 |
+
"""
|
229 |
+
with open(image_path, "rb") as image_file:
|
230 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
231 |
+
|
232 |
+
base64_image = encode_image("invoice.png")
|
233 |
+
|
234 |
+
chat_response = client.chat.completions.create(
|
235 |
+
model="numind/NuMarkdown-reasoning",
|
236 |
+
temperature=0,
|
237 |
+
messages=[
|
238 |
+
{
|
239 |
+
"role": "user",
|
240 |
+
"content": [
|
241 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}},
|
242 |
+
],
|
243 |
+
},
|
244 |
+
]
|
245 |
+
)
|
246 |
```
|