修改 Stable Diffusion 使 api 接口增加模型参数

news/2024/7/10 19:49:30 标签: python, AI作画, stable diffusion

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

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

python">StableDiffusionTxt2ImgProcessingAPI = PydanticModelGenerator(
    "StableDiffusionProcessingTxt2Img",
    StableDiffusionProcessingTxt2Img,
    [
        {"key": "sampler_index", "type": str, "default": "Euler"},
        {"key": "script_name", "type": str, "default": None},
        {"key": "script_args", "type": list, "default": []},
        {"key": "send_images", "type": bool, "default": True},
        {"key": "save_images", "type": bool, "default": False},
        {"key": "alwayson_scripts", "type": dict, "default": {}},
        {"key": "model_name", "type": str, "default": None},
    ]
).generate_model()

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

python">@dataclass(repr=False)
class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
    enable_hr: bool = False
    denoising_strength: float = 0.75
    firstphase_width: int = 0
    firstphase_height: int = 0
    hr_scale: float = 2.0
    hr_upscaler: str = None
    hr_second_pass_steps: int = 0
    hr_resize_x: int = 0
    hr_resize_y: int = 0
    hr_checkpoint_name: str = None
    hr_sampler_name: str = None
    hr_prompt: str = ''
    hr_negative_prompt: str = ''
    model_name: str = None

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

python">......

from modules import sd_samplers, deepbooru, sd_hijack, images, scripts, ui, \
    postprocessing, errors, restart, shared_items, sd_models
from modules.api import models
from modules.shared import opts, models_path

......

def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
        ......
        model_name = txt2imgreq.model_name
        if model_name is None:
            raise HTTPException(status_code=404, detail="model_name not found")
        ......
        with self.queue_lock:
            checkpoint_info = sd_models.CheckpointInfo(os.path.join(models_path, 'Stable-diffusion', model_name))
            sd_models.reload_model_weights(info=checkpoint_info)
            with closing(StableDiffusionProcessingTxt2Img(sd_model=shared.sd_model, **args)) as p:
            ......


http://www.niftyadmin.cn/n/5102245.html

相关文章

力扣-消失的数字(两种方法)

题目内容: 方法1: 根据题目我们可以知道这个数组的内容是0~N的数字,而那个消失的数字就是也是这个0~n其中一个,那么我们可以得到0~N所有的数字之和后,再将数组中的数字全部减去,那么我们就得到了那个~消失…

JS单选框默认选中样式修改,为白色背景中心有黑色小圆点的样式

要修改JavaScript中默认选中的单选框的样式为白色背景并带有黑色小圆点&#xff0c;你可以使用CSS来实现。以下是一个示例&#xff0c;展示如何修改样式&#xff1a; <style>/* 修改默认选中单选框的样式 */input[type"radio"]:checked {appearance: none; /*…

Android平台GB28181设备接入模块之SmartGBD

大牛直播SDK研发的Android平台GB28181设备接入SDK&#xff08;SmartGBD&#xff09;&#xff0c;可实现不具备国标音视频能力的 Android终端&#xff0c;通过平台注册接入到现有的GB/T28181—2016服务&#xff0c;可用于如执法记录仪、智能安全帽、智能监控、智慧零售、智慧教育…

14.v3+ts的keepalive

1.缓存在内的组件值 <template><div class"container"><button click"flag !flag">切換</button><KeepAlive><Foot v-if"flag"></Foot><Content v-else></Content></KeepAlive>&…

笙默考试管理系统-MyExamTest----codemirror(35)

笙默考试管理系统-MyExamTest----codemirror&#xff08;35&#xff09; 目录 一、 笙默考试管理系统-MyExamTest 二、 笙默考试管理系统-MyExamTest 三、 笙默考试管理系统-MyExamTest 四、 笙默考试管理系统-MyExamTest 五、 笙默考试管理系统-MyExamTest 笙默考试…

【LeetCode】45. 跳跃游戏 II

1 问题 给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。 每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说&#xff0c;如果你在 nums[i] 处&#xff0c;你可以跳转到任意 nums[i j] 处: 0 < j < nums[i] i j < n 返回到达 nums[n -…

Gson FastJson Jackson 出来 Date LocalDate LocalDateTime 日期类型JSON格式字符串

Gson FastJson Jackson 处理 Date LocalDate LocalDateTime 日期类型JSON格式字符串 Gson 处理 Date LocalDate LocalDateTime 日期类型JSON格式字符串 要在使用Gson库进行属性为Date、LocalDate和LocalDateTime的对象的序列化和反序列化时&#xff0c; 可以使用注解来指定日期…

Android 优化 - 磁盘缓存DiskLruCache

一、概念 用于实现存储设备缓存&#xff0c;即磁盘缓存&#xff0c;通过将缓存对象写入文件系统从而实现缓存的效果。 二、使用 2.1 添加依赖 最新依赖 implementation "com.jakewharton:disklrucache:2.0.2" 2.2 配置权限 <uses-permission android:name&qu…