• 修改 Stable Diffusion 使 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
  • 相关阅读:
    myj的尘歌壶
    Seata概述
    2023.11.14-hive之表操作练习和文件导入练习
    分库分表问题
    第二十七章HTML.CSS综合案例(二)
    MVC第三波书店书籍首页展示页面
    Nessus安装与使用
    java毕业设计校园二手交易网站mybatis+源码+调试部署+系统+数据库+lw
    【运筹优化】运筹学导论:线性规划导论
    023-从零搭建微服务-推送服务(三)
  • 原文地址:https://blog.csdn.net/dszgf5717/article/details/133910976