当前位置:   article > 正文

修改 Stable Diffusion 使 api 接口增加模型参数_stable-diffusion-webui api接口可以扩展参数?

stable-diffusion-webui api接口可以扩展参数?

 参考:https://zhuanlan.zhihu.com/p/644545784

1、修改 modules/api/models.py 中的 StableDiffusionTxt2ImgProcessingAPI 增加模型名称

  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. {"key": "model_name", "type": str, "default": None},
  12. ]
  13. ).generate_model()

 2、修改 modules/api/api.py 中 text2imgapi 代码:

  1. ......
  2. from modules import sd_samplers, deepbooru, sd_hijack, images, scripts, ui, \
  3. postprocessing, errors, restart, shared_items, sd_models
  4. from modules.api import models
  5. from modules.shared import opts, models_path
  6. ......
  7. def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
  8. ......
  9. with self.queue_lock:
  10. if txt2imgreq.model_name is not None:
  11. checkpoint_info = sd_models.CheckpointInfo(os.path.join(models_path,
  12. 'Stable-diffusion', txt2imgreq.model_name))
  13. sd_models.reload_model_weights(info = checkpoint_info)
  14. with closing(StableDiffusionProcessingTxt2Img(sd_model=shared.sd_model, **args)) as p:
  15. ......

 3、修改 modules/processing.py 中的 StableDiffusionProcessingTxt2Img,增加模型名称接收

  1. @dataclass(repr=False)
  2. class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
  3. enable_hr: bool = False
  4. denoising_strength: float = 0.75
  5. firstphase_width: int = 0
  6. firstphase_height: int = 0
  7. hr_scale: float = 2.0
  8. hr_upscaler: str = None
  9. hr_second_pass_steps: int = 0
  10. hr_resize_x: int = 0
  11. hr_resize_y: int = 0
  12. hr_checkpoint_name: str = None
  13. hr_sampler_name: str = None
  14. hr_prompt: str = ''
  15. hr_negative_prompt: str = ''
  16. model_name: str = None
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/104638
推荐阅读
相关标签
  

闽ICP备14008679号