import base64
from io import BytesIO
from PIL import Image
import requests
image_path = "xxx.jpeg"
def image_to_base64(image_path):
image = Image.open(image_path)
buffered = BytesIO()
image.save(buffered, format="JPEG")
return base64.b64encode(buffered.getvalue()).decode()
base64_string = image_to_base64(image_path)
url = "http://127.0.0.1:11434/api/generate"
data = {
"model": "qwen2.5vl:3b",
"prompt": "請描述這張圖片的內容",
"stream": False,
# "images": [base64_string]
}
response = requests.post(url, json=data)
print("模型返回:", response.json())
{'model': 'qwen2.5vl:3b', 'created_at': '2025-10-29T03:53:47.159861832Z', 'response': '很抱歉,我無法提供圖片內容的描述,因為我無法看到您所指的圖片。如果您能提供圖片的連結或描述,我將很樂意幫您分析和描述。', 'done': True, 'done_reason': 'stop', 'context': [151644, 8948, 198, 2610, 525, 264, 10950, 17847, 13, 151645, 198, 151644, 872, 198, 100792, 53481, 99672, 102523, 112426, 9370, 102291, 3837, 106360, 32757, 117625, 3837, 100630, 99885, 101590, 19793, 5373, 87335, 57191, 102701, 82699, 65278, 111774, 1773, 151645, 198, 151644, 77091, 198, 99165, 115546, 3837, 35946, 105704, 99553, 112426, 102291, 9370, 53481, 3837, 104344, 35946, 105704, 101038, 87026, 31838, 63367, 9370, 112426, 1773, 106870, 26232, 99553, 112426, 9370, 110842, 57191, 53481, 3837, 35946, 101110, 99165, 100923, 36589, 103307, 87026, 101042, 33108, 53481, 1773], 'total_duration': 2391630459, 'load_duration': 80904137, 'prompt_eval_count': 44, 'prompt_eval_duration': 584403227, 'eval_count': 42, 'eval_duration': 1696579552}
How can I fix this? Thanks