Magma-8B / validation /hf_deployment_validation.py
xuanzhaopeng's picture
Validation
ef85a7a
import requests
import base64
# Hugging Face Endpoint
HF_TOKEN = "hf_<>"
HF_ENDPOINT = "https://"
# 读取本地图片并转换为 Base64
def encode_image(image_path):
with open(image_path, "rb") as f:
return base64.b64encode(f.read()).decode("utf-8")
# 构造请求数据
image_base64 = encode_image("./test.png")
payload = {
"inputs": { # Wrap everything inside "inputs"
"image": image_base64, # 发送 Base64 编码的图片
"convs": [
{"role": "system", "content": "You are agent that can see, talk and act."},
{"role": "user", "content": "<image_start><image><image_end>\nWhat is in this image?"}
]
}
}
# 发送请求
headers = {
"Accept" : "application/json",
"Content-Type": "application/json",
"Authorization": f"Bearer {HF_TOKEN}",
}
response = requests.post(HF_ENDPOINT, headers=headers, json=payload)
# 解析响应
if response.status_code == 200:
print("Response:", response.json())
else:
print("Error:", response.status_code, response.text)