Python Aliyun 通义万相

from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis

def simple_call():
    prompt = '1girl,(ulzzang-6500:0.7), kpop idol, yae miko, detached sleeves, bare shoulders, pink hair, long hair, japanese clothes, best quality, (painting:1.5), (hair ornament:1.35), jewelry, purple eyes, earrings, breasts, torii, cherry blossoms, lantern light, depth of field, detailed face, face focus, ribbon_trim, (looking at viewer:1.25), nontraditional miko, shiny skin, long sleeves, smile, thick lips, game cg, hands on lips, east asian architecture, (blurry background:1.2), sitting, upper body,'
    negative_prompt = '''
        bright lantern, brightness,(nipples:1.2), pussy, EasyNegative, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans,extra fingers, fewer fingers, strange fingers, bad hand, bare thighs

        ENSD:1337, Size:480x640, Seed:2539119551, Model: sunshinemix_CkptNoVAE, Steps:20,

        Sampler: DPM++ SDE, CFG scale:6, Clip skip:2, Model hash:08007f7225,

        Hires steps:10, Hires upscale:1.5, AddNet Enabled: True, AddNet Model1: koreanDollLikeness_v10(e2e472c06607),

        AddNet Model2: YaeMiko_Test(8eafb307ecf8), Hires upscaler: Latent, AddNet Module1: LoRA,

        AddNet Module2: LoRA, AddNet Weight A1:0.25, AddNet Weight A2:0.75,

        AddNet Weight B1:0.25, AddNet Weight B2:0.75, Denoising strength:0.7
    '''

    prompt2 = """
    <lora:ganyu_ned2_offset:1> <lora:japaneseDollLikeness_v10:0.45> masterpiece, (photorealistic:1.5), best quality, beautiful lighting, real life,
    ganyu \(genshin impact\),1girl, ahoge, architecture, bangs, bare shoulders, bell, black gloves, black pantyhose, (blue hair), blush, breasts, chinese knot, detached sleeves, east asian architecture, flower knot, gloves, horns, long hair, looking at viewer, medium breasts, neck bell, night, outdoors, pantyhose, purple eyes, sidelocks, solo, tassel, white sleeves, (ulzzang-6500:0.5), intricate, high detail, sharp focus, dramatic, beautiful girl , (RAW photo,8k uhd, film grain), caustics, subsurface scattering, reflections
    """
    negative_prompt2 = """
    (painting by bad-artist-anime:0.9), (painting by bad-artist:0.9), watermark, text, error, blurry, jpeg artifacts, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, artist name, (worst quality, low quality:1.4), bad anatomy

    ENSD:31337, Size:896x1344, Seed:1380816974, Model: NeverEndingDream_ft_mse,

    Steps:30, Sampler: DPM++ SDE Karras, CFG scale:9, Clip skip:2, Mask blur:4,

    Model hash: d8722b4a4d, Denoising strength:0.4
    """

    rsp = ImageSynthesis.call(model=ImageSynthesis.Models.wanx_v1,
                              api_key='xxxxxxxxxxxxxxxxxxxxxxxxxxx',
                              prompt=prompt2,
                              negative_prompt=negative_prompt2,
                              n=4,
                              size='1024*1024')
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output)
        print(rsp.usage)
        # save file to current directory
        for result in rsp.output.results:
            file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
            with open('./img/%s' % file_name, 'wb+') as f:
                f.write(requests.get(result.url).content)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

if __name__ == '__main__':
    simple_call()