modelscope平台API推理
·
设置访问令牌:https://modelscope.cn/my/myaccesstoken
API Inference文档:https://www.modelscope.cn/docs/model-service/API-Inference/intro
import requests
import json
from PIL import Image
from io import BytesIO
url = 'https://api-inference.modelscope.cn/v1/images/generations'
payload = {
'model': 'raoxiaoya/zhaominplus', # ModelScope Model-Id,required
'prompt': 'A person dressed in traditional Chinese clothing, exquisitely styled, riding majestically on horseback, holding a folding fan in one hand, with a powerful and commanding gaze.' # required
}
headers = {
'Authorization': 'Bearer API令牌', # 这个 Bearer 不能删
'Content-Type': 'application/json'
}
response = requests.post(url, data=json.dumps(
payload, ensure_ascii=False).encode('utf-8'), headers=headers)
response_data = response.json()
image = Image.open(BytesIO(requests.get(
response_data['images'][0]['url']).content))
image.save('result_image.jpg')
参数说明
| 参数名 | 参数说明 | 是否必须 | 参数类型 | 示例 | 取值范围 |
|---|---|---|---|---|---|
| model | 模型id | 是 | string | MAILAND/majicflus_v1 | ModelScope上的AIGC 模型ID |
| prompt | 正向提示词,大部分模型建议使用英文提示词效果较好。 | 是 | string | A mysterious girl walking down the corridor. | 长度小于2000 |
| negative_prompt | 负向提示词 | 否 | string | lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry | 长度小于2000 |
| size | 生成图像分辨率大小 | 否 | string | 1024x1024 | SD系列:[64x64,2048x2048],FLUX:[64x64,1024x1024] |
| seed | 随机种子 | 否 | int | 12345 | [0,2^31-1] |
| steps | 采样步数 | 否 | int | 30 | [1,100] |
| guidance | 提示词引导系数 | 否 | float | 3.5 | [1.5,20] |
更多推荐




所有评论(0)