编辑
2025-03-19
深度学习
00

拉取:

docker pull vllm/vllm-openai:latest

启动:

docker run -d --gpus '"device=1,3"' \ -v ./zizhi_merge_2025-1:/Qwen2-VL-Any \ -p 7871:8000 \ --ipc=host \ --shm-size 16g \ vllm/vllm-openai:latest \ --model /Qwen2-VL-Any --gpu_memory_utilization 0.9 --tensor_parallel_size 2

访问:

python
import base64 import requests def analyze_custom_image(): # 配置服务器信息 server_ip = "101.136.19.26" port = 7871 api_endpoint = f"http://{server_ip}:{port}/v1/chat/completions" # 认证信息(需与服务器启动参数一致) api_key = "token-abc123" # 替换为实际API密钥 try: # 1. 读取并编码本地PNG图片 with open("yiliao.png", "rb") as img_file: base64_data = base64.b64encode(img_file.read()).decode('utf-8') # 2. 构建请求头 headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } # 3. 组装请求体 payload = { "model": "/Qwen2-VL-Any", # 确认模型名称与服务器一致 "messages": [ { "role": "user", "content": [ {"type": "text", "text": text_a}, { "type": "image_url", "image_url": { # 修改MIME类型为image/png "url": f"data:image/png;base64,{base64_data}" } } ] } ], "max_tokens": 4096 # 增加token限额以获取更详细描述 } # 4. 发送请求 response = requests.post(api_endpoint, headers=headers, json=payload) response.raise_for_status() # 自动抛出HTTP错误 # 5. 解析结果 result = response.json()["choices"][0]["message"]["content"] return f"医疗图像分析结果:\n{result}" except requests.exceptions.RequestException as e: return f"网络请求失败:{str(e)}" except KeyError: return f"响应格式异常,原始响应:{response.text}" except Exception as e: return f"未知错误:{str(e)}" # 执行分析 if __name__ == "__main__": analysis_result = analyze_custom_image() print(analysis_result)
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!

评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.14.8