当前位置:   article > 正文

stable-diffusion-webui之api_sdwebui javaapi

sdwebui javaapi

Basic Documentation and Examples for using API · AUTOMATIC1111/stable-diffusion-webui · Discussion #3734 · GitHubBasic Documentation and Examples for using APIicon-default.png?t=N7T8https://github.com/AUTOMATIC1111/stable-diffusion-webui/discussions/3734

GitHub - mix1009/sdwebuiapi: Python API client for AUTOMATIC1111/stable-diffusion-webuiPython API client for AUTOMATIC1111/stable-diffusion-webui - GitHub - mix1009/sdwebuiapi: Python API client for AUTOMATIC1111/stable-diffusion-webuiicon-default.png?t=N7T8https://github.com/mix1009/sdwebuiapi 

  1. python webui.py --port 7860 --nowebui --listen
  2. 在http://127.0.0.1:7860/docs中可以看到
  1. python webui.py --port 7860 --nowebui --listen
  2. api_only()->initialize()->
  3. app = Fastapi()->setup_middleware(app)->api=Api(app,queue_lock)->
  4. modules.script_callbacks.app_started_callback(None,app)
  5. api.launch()

modules/api/api.py 

  1. self.router = APIRouter()
  2. api_middleware(self.app)
  3. self.add_api_route("/sdapi/v1/txt2img", self.text2imgapi, methods=["POST"], response_model=models.TextToImageResponse)
  4. text2imgapi()->
  5. script_runner = scripts.scripts_txt2img
  6. if not script_runner.scripts:
  7. script_runner.initialize_scripts(False)
  8. ui.create_ui()
  9. if not self.default_script_arg_txt2img:
  10. self.default_script_arg_txt2img = self.init_default_script_args(script_runner)
  11. selectable_scripts, selectable_script_idx = self.get_selectable_script(txt2imgreq.script_name, script_runner)
  12. populate = txt2imgreq.copy(update={ # Override __init__ params
  13. "sampler_name": validate_sampler_name(txt2imgreq.sampler_name or txt2imgreq.sampler_index),
  14. "do_not_save_samples": not txt2imgreq.save_images,
  15. "do_not_save_grid": not txt2imgreq.save_images,
  16. })
  17. if populate.sampler_name:
  18. populate.sampler_index = None # prevent a warning later on
  19. args = vars(populate)
  20. args.pop('script_name', None)
  21. args.pop('script_args', None) # will refeed them to the pipeline directly after initializing them
  22. args.pop('alwayson_scripts', None)
  23. script_args = self.init_script_args(txt2imgreq, self.default_script_arg_txt2img, selectable_scripts,
  24. selectable_script_idx, script_runner)
  25. send_images = args.pop('send_images', True)
  26. args.pop('save_images', None)
  27. with self.queue_lock:
  28. p = StableDiffusionProcessingTxt2Img(sd_model=shared.sd_model, **args)
  29. p.scripts = script_runner
  30. p.outpath_grids = opts.outdir_txt2img_grids
  31. p.outpath_samples = opts.outdir_txt2img_samples
  32. shared.state.begin()
  33. if selectable_scripts is not None:
  34. p.script_args = script_args
  35. processed = scripts.scripts_txt2img.run(p, *p.script_args) # Need to pass args as list here
  36. else:
  37. p.script_args = tuple(script_args) # Need to pass args as tuple here
  38. processed = process_images(p)
  39. shared.state.end()
  40. b64images = list(map(encode_pil_to_base64, processed.images)) if send_images else []
  41. return models.TextToImageResponse(images=b64images, parameters=vars(txt2imgreq), info=processed.js())

/modules/api/models.py

  1. StableDiffusionTxt2ImgProcessingAPI = PydanticModelGenerator(
  2. "StableDiffusionProcessingTxt2Img",
  3. StableDiffusionProcessingTxt2Img,
  4. [
  5. {"key": "sampler_index", "type": str, "default": "Euler"},
  6. {"key": "script_name", "type": str, "default": None},
  7. {"key": "script_args", "type": list, "default": []},
  8. {"key": "send_images", "type": bool, "default": True},
  9. {"key": "save_images", "type": bool, "default": False},
  10. {"key": "alwayson_scripts", "type": dict, "default": {}},
  11. ]
  12. ).generate_model()

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号