AI画图 Ubuntu 20.04.5 LTS x86_64 Docker stable diffusion webui 及 http api接口

2023-05-16

资源

Docker镜像

docker pull darkroot1234/ayanami:latest

参考地址:

docker一键运行stable diffusion webui,常用插件和功能完备,获得镜像后可打包带走 - 哔哩哔哩

nvidia cuda 驱动

​​​​​​​Linux x64 (AMD64/EM64T) Display Driver | 525.116.04 | Linux 64-bit | NVIDIA

lora模型下载

热门Civitai LoRA模型下载第一批合集 Stable Diffusion WebUI - openAI

启动

docker run --gpus all -it -p 8888:8888 -p 7860:7860 -p 6666:22 --name ayanami --ipc=host darkroot1234/ayanami:latest

注意:启动时会访问公网,如果网络不通,会导致启动失败,注意看docker日志输出

docker cp 拷贝模型文件到容器/workspace/models/Stable-diffusion/目录下:chilloutmix_Ni.safetensors 

重启docker

docker restart ayanami

等待加载资源,打开浏览器,访问 http://127.0.0.1:7860

左上角选择放入的模型,采用该容器自带的参数,生成绫波丽

 

 修改参数,去掉CAD,机器人等信息

((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,

http api

请求

通过观察浏览器请求,发现首次触发生成时,第一条请求predict/卡在pending状态,当渲染结束后,该请求响应出了图片地址

 复制出来的curl指令

curl 'http://127.0.0.1:7860/run/predict/' \
  -H 'Accept: */*' \
  -H 'Accept-Language: zh,en-US;q=0.9,en;q=0.8' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: _ga=GA1.1.1067480164.1660637226' \
  -H 'Origin: http://127.0.0.1:7860' \
  -H 'Referer: http://127.0.0.1:7860/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Linux"' \
  --data-raw $'{"fn_index":102,"data":["((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,","","None","None",50,"Euler a",false,false,1,1,11,2083545561,-1,0,0,0,false,704,1024,false,0.7,0,0,"None",false,false,false,false,"","Seed","","Nothing","",true,false,false,null,"{\\"prompt\\": \\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\\", \\"all_prompts\\": [\\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\\"], \\"negative_prompt\\": \\"\\", \\"all_negative_prompts\\": [\\"\\"], \\"seed\\": 2083545561, \\"all_seeds\\": [2083545561], \\"subseed\\": 1093441852, \\"all_subseeds\\": [1093441852], \\"subseed_strength\\": 0, \\"width\\": 1024, \\"height\\": 704, \\"sampler_name\\": \\"Euler a\\", \\"cfg_scale\\": 11, \\"steps\\": 50, \\"batch_size\\": 1, \\"restore_faces\\": false, \\"face_restoration_model\\": null, \\"sd_model_hash\\": \\"8c3b86ce\\", \\"seed_resize_from_w\\": 0, \\"seed_resize_from_h\\": 0, \\"denoising_strength\\": null, \\"extra_generation_params\\": {}, \\"index_of_first_image\\": 0, \\"infotexts\\": [\\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\\\\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2\\"], \\"styles\\": [\\"None\\", \\"None\\"], \\"job_timestamp\\": \\"20230511015740\\", \\"clip_skip\\": 2, \\"is_using_inpainting_conditioning\\": false}","<p>((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,<br>\\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2</p><div class=\'performance\'><p class=\'time\'>Time taken: <wbr>24.71s</p><p class=\'vram\'>Torch active/reserved: 3573/4222 MiB, <wbr>Sys VRAM: 5882/5924 MiB (99.29%)</p></div>"],"session_hash":"t3m95wa7oj"}' \
  --compressed

其中我们填写的参数在data数组的第一段字符串参数内,即

((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,

第二个参数标识第二个输入框,我们没有输入。

响应

该请求会阻塞,直到渲染结束

{"data":[[{"name":"outputs/txt2img-images/00054-2083545561-((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,.png","data":null,"is_file":true}],"{\"prompt\": \"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\", \"all_prompts\": [\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\"], \"negative_prompt\": \"\", \"all_negative_prompts\": [\"\"], \"seed\": 2083545561, \"all_seeds\": [2083545561], \"subseed\": 881369708, \"all_subseeds\": [881369708], \"subseed_strength\": 0, \"width\": 1024, \"height\": 704, \"sampler_name\": \"Euler a\", \"cfg_scale\": 11, \"steps\": 50, \"batch_size\": 1, \"restore_faces\": false, \"face_restoration_model\": null, \"sd_model_hash\": \"8c3b86ce\", \"seed_resize_from_w\": 0, \"seed_resize_from_h\": 0, \"denoising_strength\": null, \"extra_generation_params\": {}, \"index_of_first_image\": 0, \"infotexts\": [\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2\"], \"styles\": [\"None\", \"None\"], \"job_timestamp\": \"20230511015814\", \"clip_skip\": 2, \"is_using_inpainting_conditioning\": false}","<p>((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,<br>\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2</p><div class='performance'><p class='time'>Time taken: <wbr>24.88s</p><p class='vram'>Torch active/reserved: 3573/3980 MiB, <wbr>Sys VRAM: 5665/5924 MiB (95.63%)</p></div>"],"is_generating":false,"duration":24.88272213935852,"average_duration":34.33394391720112}

其中name字段为生成图片的文件名,访问方式

http://127.0.0.1:7860/file=outputs/txt2img-images/00054-2083545561-((masterpiece)),%20((best%20quality)),((extremely%20detailed)),Ayanami%20Rei,beautiful%20face,Blue%20hair,Beautiful%20red%20eyes,.png

即:固定url前段

http://127.0.0.1:7860/file=

拼接上文件名,注意:文件名应当采用urlencode编码

效果

 该文件位于容器路径

/workspace/outputs/txt2img-images/ 

注意:该路径不会自动清理,如果大量生成,需要自行考虑把该目录挂载到分布式存储上,如glasterfs,需要自行设计清理程序。

进度查询

curl 'http://127.0.0.1:7860/run/predict/' \
  -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
  -H 'sec-ch-ua-platform: "Linux"' \
  -H 'Referer: http://127.0.0.1:7860/' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
  -H 'Content-Type: application/json' \
  --data-raw '{"fn_index":88,"data":[],"session_hash":"t3m95wa7oj"}' \
  --compressed

响应

进行中

{"data":["<span id='txt2img_progress_span' style='display: none'>1683771458.0030112</span><p><div class='progressDiv'><div class='progress' style=\"overflow:visible;width:98.0%;white-space:nowrap;\">&nbsp;&nbsp;98% ETA: 00s</div></div></p>",{"visible":false,"__type__":"update"},{"visible":false,"__type__":"update"},{"visible":false,"__type__":"update"}],"is_generating":false,"duration":0.0002410411834716797,"average_duration":0.0002521400164840813}

完成

{"data":["",{"visible":false,"__type__":"update"},{"visible":false,"__type__":"update"},{"visible":false,"__type__":"update"}],"is_generating":false,"duration":0.0005140304565429688,"average_duration":0.0002525332453730586}

api差异说明

fn_indexdatasession_hash
生成api102必填必填
查询api88留空必填(保持与生成api一致)

http api调佣测试

主要参数修改为

((masterpiece)), ((best quality)),((extremely detailed)),beautiful face,Beautiful eyes,

完整curl指令

curl 'http://127.0.0.1:7860/run/predict/' \
  -H 'Accept: */*' \
  -H 'Accept-Language: zh,en-US;q=0.9,en;q=0.8' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: _ga=GA1.1.1067480164.1660637226' \
  -H 'Origin: http://127.0.0.1:7860' \
  -H 'Referer: http://127.0.0.1:7860/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Linux"' \
  --data-raw $'{"fn_index":102,"data":["((masterpiece)), ((best quality)),((extremely detailed)),beautiful face,Beautiful eyes,","","None","None",50,"Euler a",false,false,1,1,11,2083545561,-1,0,0,0,false,704,1024,false,0.7,0,0,"None",false,false,false,false,"","Seed","","Nothing","",true,false,false,null,"{\\"prompt\\": \\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\\", \\"all_prompts\\": [\\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\\"], \\"negative_prompt\\": \\"\\", \\"all_negative_prompts\\": [\\"\\"], \\"seed\\": 2083545561, \\"all_seeds\\": [2083545561], \\"subseed\\": 1093441852, \\"all_subseeds\\": [1093441852], \\"subseed_strength\\": 0, \\"width\\": 1024, \\"height\\": 704, \\"sampler_name\\": \\"Euler a\\", \\"cfg_scale\\": 11, \\"steps\\": 50, \\"batch_size\\": 1, \\"restore_faces\\": false, \\"face_restoration_model\\": null, \\"sd_model_hash\\": \\"8c3b86ce\\", \\"seed_resize_from_w\\": 0, \\"seed_resize_from_h\\": 0, \\"denoising_strength\\": null, \\"extra_generation_params\\": {}, \\"index_of_first_image\\": 0, \\"infotexts\\": [\\"((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,\\\\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2\\"], \\"styles\\": [\\"None\\", \\"None\\"], \\"job_timestamp\\": \\"20230511015740\\", \\"clip_skip\\": 2, \\"is_using_inpainting_conditioning\\": false}","<p>((masterpiece)), ((best quality)),((extremely detailed)),Ayanami Rei,beautiful face,Blue hair,Beautiful red eyes,<br>\\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2</p><div class=\'performance\'><p class=\'time\'>Time taken: <wbr>24.71s</p><p class=\'vram\'>Torch active/reserved: 3573/4222 MiB, <wbr>Sys VRAM: 5882/5924 MiB (99.29%)</p></div>"],"session_hash":"t3m95wa7oj"}' \
  --compressed

响应(约15秒)

{"data":[[{"name":"outputs/txt2img-images/00055-2083545561-((masterpiece)), ((best quality)),((extremely detailed)),beautiful face,Beautiful eyes,.png","data":null,"is_file":true}],"{\"prompt\": \"((masterpiece)), ((best quality)),((extremely detailed)),beautiful face,Beautiful eyes,\", \"all_prompts\": [\"((masterpiece)), ((best quality)),((extremely detailed)),beautiful face,Beautiful eyes,\"], \"negative_prompt\": \"\", \"all_negative_prompts\": [\"\"], \"seed\": 2083545561, \"all_seeds\": [2083545561], \"subseed\": 501878245, \"all_subseeds\": [501878245], \"subseed_strength\": 0, \"width\": 1024, \"height\": 704, \"sampler_name\": \"Euler a\", \"cfg_scale\": 11, \"steps\": 50, \"batch_size\": 1, \"restore_faces\": false, \"face_restoration_model\": null, \"sd_model_hash\": \"8c3b86ce\", \"seed_resize_from_w\": 0, \"seed_resize_from_h\": 0, \"denoising_strength\": null, \"extra_generation_params\": {}, \"index_of_first_image\": 0, \"infotexts\": [\"((masterpiece)), ((best quality)),((extremely detailed)),beautiful face,Beautiful eyes,\\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2\"], \"styles\": [\"None\", \"None\"], \"job_timestamp\": \"20230511021329\", \"clip_skip\": 2, \"is_using_inpainting_conditioning\": false}","<p>((masterpiece)), ((best quality)),((extremely detailed)),beautiful face,Beautiful eyes,<br>\nSteps: 50, Sampler: Euler a, CFG scale: 11, Seed: 2083545561, Size: 1024x704, Model hash: 8c3b86ce, Clip skip: 2</p><div class='performance'><p class='time'>Time taken: <wbr>24.41s</p><p class='vram'>Torch active/reserved: 3573/4222 MiB, <wbr>Sys VRAM: 5853/5924 MiB (98.8%)</p></div>"],"is_generating":false,"duration":24.41366720199585,"average_duration":33.62535272325788}

拼接出图片地址

http://127.0.0.1:7860/file=outputs/txt2img-images/00055-2083545561-((masterpiece)),%20((best%20quality)),((extremely%20detailed)),beautiful%20face,Beautiful%20eyes,.png

访问

处理时,gpu负载

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AI画图 Ubuntu 20.04.5 LTS x86_64 Docker stable diffusion webui 及 http api接口 的相关文章

随机推荐