设置访问令牌: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]
Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐