stable diffusion的api参数-附带插件使用

stable diffusion 的 webui中api的使用,包括lora,controlnet、roop、vae等模块。 欢迎留言加群详细交流

{
    "prompt": "(masterpiece, best quality,Refined, beautiful),haruno sakura",
    "negative_prompt": " ((((big hands, un-detailed skin, semi-realistic)))), (((ugly mouth, ugly eyes,The disabled eyes, blurred eyes, missing teeth, crooked teeth, close up, cropped, out of frame))), worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck,Deforming fingers, incomplete fingers, extra fingers,Ugly face",
    "override_settings": {
        "sd_model_checkpoint": "MXCFSuper_Counterfeit/mxcfSuperCounterfeit_v10.safetensors [56c0585d87]",
        "sd_vae": "YOZORA.vae.pt"
    },
    "clip_skip": 2,
    "denoising_strength": 0.5,
    "seed": -1,
    "batch_size": 1,
    "n_iter": 1,
    "steps": 25,
    "cfg_scale": 7,
    "restore_faces": False,
    "sampler_index": "DPM++ SDE Karras",
    "resize_mode": 1, # "mask_blur": 10, # "tiling": False, # "eta": 0, # "script_args": [], # "inpainting_fill": 1, # "inpaint_full_res": True, # "inpaint_full_res_padding": 32, # "inpainting_mask_invert": 1,
    "alwayson_scripts": {
        "other plugin": {
            "args": [arg1, arg2
            ]
        } "ControlNet": {
            "args": [
                {
                    "enabled": True,
                    "input_image": "",
                    "mask": None,
                    "module": "canny",
                    "model": "control_sd15_canny [fef5e48e]",
                    "weight": 1,
                    "invert_image": False,
                    "resize_mode": 1,
                    "rgbbgr_mode": False,
                    "lowvram": False,
                    "processor_res": 512,
                    "threshold_a": 100,
                    "threshold_b": 200,
                    "starting_control_step": 0,
                    "ending_control_step": 1, # "guidance": 1, # "guidance_start": 0, # "guidance_end": 1,
                    "guessmode": False
                }
            ]
        }
    }
}

参数解释:

模型:MXCFSuper_Counterfeit

VAE:none

Clip skip:2 

Prompt:

Negative Prompt:””

Resize mode:Just resize

Sampling method:DPM++ SDE Karras

Sampling steps:25

Restore faces:flase

Width:所传图片宽度

Height:所传图片高度

Batch count:1

Batch size:1

CFG Scale:5

Denoising strength:0.5

Seed:-1

ControlNet:Enable

Control Type:Canny

Preprocessor:Canny

Model:control_sd15_canny

Control Weight:1

Starting Control Step:0

Ending Control Step:1

Preprocessor Resolution:512

Canny Low Threshold:100

Canny Hight Threshold:200

Control Mode:Balanced

Resize Mode:Crop and Resize

Script:none

python获取print的输入内容

因为print是输出到sys.out里面, 所以要替换标准的输出:


#coding: utf-8

class TextArea(object):

    def __init__(self):
        self.buffer = []

    def write(self, *args, **kwargs):
        self.buffer.append(args)

import sys

stdout = sys.stdout
sys.stdout = TextArea()

# print to TextArea
print("testA")
print("testB")
print("testC")

text_area, sys.stdout = sys.stdout, stdout

# print to console
print(text_area.buffer)
输出内容:
[('testA',), ('\n',), ('testB',), ('\n',), ('testC',), ('\n',)]

如果是json数据,可以增加一步处理:

data_get_json_ori = text_area.buffer[0]  # json
data_get_json = json.loads(data_get_json_ori)

data_get= {}
host = ''
for key, value in data_get_json.items():
data_get[key] = value

ubuntu18安装Python3.7

  1. ubuntu18系统自带了python2.7和python3.6;
  2. 不要卸载ubuntu自带的python版本;
  3. ubuntu下不同版本的python可以共存,可直接安装python3.7。

1.升级包索引和软件

sudo apt update
sudo apt upgrade -y

2.安装编译所需包

sudo apt install build-essential zlib1g-dev libbz2-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

3.下载Python3.7

官网下载Python-3.7.4.tgz文件

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

4.解压Python安装包

tar -xzvf Python-3.7.4.tgz

5.编译和安装

cd Python-3.7.4
./configure --prefix=/usr/local/src/python37  # 配置安装位置
sudo make
sudo make install

6.建立软连接

sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python3.7
sudo ln -s /usr/local/src/python37/bin/pip3.7 /usr/bin/pip3.7

接下来你就可以使用python3.7,而不会影响系统自带的python2.7和python3.6

如果你想用python3.7替换掉系统默认的python3

sudo rm -rf /usr/bin/python3
sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python3

默认ubuntu系统中没有pip3,直接建立软连接即可。
sudo ln -s /usr/local/src/python37/bin/pip3.7 /usr/bin/pip3

输入python3默认就是你安装好的python3.7了

scrapy提供接口服务

将scrapy发布为服务并提供接口服务,以便其他项目调用:

  • pip install scrapyd
  • pip install scrapyd-client
  • 修改scrapy.cfg:
  • 启动服务:scrapyd

[settings]
default = compass.settings

[deploy]
url = http://localhost:6800/
project = compass[settings]

  • 部署服务:scrapyd-deploy
  • 启动服务:scrapyd
  • 调用服务:curl http://localhost:6800/schedule.json -d project=your_project_name -d spider=your_spider_name
  • 不清楚项目名和爬虫名可以用下面命令查询:
    • 列出项目:curl http://localhost:6800/listprojects.json
    • 列出爬虫:curl http://localhost:6800/listspiders.json?project=compass
  • 其他命令:
    • 调度爬虫
      • curl http://localhost:6800/schedule.json -d project=your_project_name -d spider=your_spider_name
    • 包含参数
      • curl http://localhost:6800/schedule.json -d project=your_project_name -d spider=your_spider_name -d setting=DOWNLOAD_DELAY=2 -d arg1=val1
    • 取消运行
      • curl http://localhost:6800/cancel.json -d project=your_project_name -d job=2bffadcb3218k9abbd23ccf016aa82f02
    • 列出版本
      • curl http://localhost:6800/listversions.json?project=your_project_name
    • 列出job
      • curl http://localhost:6800/listjobs.json?project=your_project_name
    • 删除版本
      • curl http://localhost:6800/delversion.json -d project=your_project_name -d version==15419782769
    • 删除项目
      • curl http://localhost:6800/delproject.json -d project=your_project_name