Created
February 28, 2025 17:59
-
-
Save jgonera/326ff5d1612a72d0b80194636146f38c to your computer and use it in GitHub Desktop.
mistral.rs test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import requests | |
def encode_image_to_base64(image_path): | |
with open(image_path, "rb") as image_file: | |
return base64.b64encode(image_file.read()).decode('utf-8') | |
def perform_ocr(image_path): | |
base64_image = encode_image_to_base64(image_path) | |
response = requests.post( | |
"http://localhost:9000/v1/chat/completions", | |
json={ | |
"model":"minicpmo_2_6", | |
"messages": [ | |
{ | |
"role": "user", | |
"content": [ | |
{ | |
"type": "image_url", | |
"image_url": { | |
"url": "https://www.nhmagazine.com/content/uploads/2019/05/mtwashingtonFranconia-2-19-18-108-Edit-Edit.jpg" | |
}, | |
}, | |
{ | |
"type": "text", | |
"text": "(<image>./</image>) What is shown in this image? Write a detailed response analyzing the scene.", | |
}, | |
], | |
# "content": "What is your name?", | |
} | |
], | |
"max_tokens": 256, | |
"frequency_penalty": 1.0, | |
"top_p": 0.1, | |
"temperature": 0, | |
} | |
) | |
return response.text | |
if __name__ == "__main__": | |
image_path = "../images/plain.jpg" | |
result = perform_ocr(image_path) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment