Skip to content

Commit

Permalink
Use existing function for old sampler names
Browse files Browse the repository at this point in the history
  • Loading branch information
missionfloyd authored and w-e-w committed May 15, 2024
1 parent 9f8ba75 commit 4482131
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions modules/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ def validate_sampler_name(name):
return name


def parse_old_sampler_name(name):
for scheduler in sd_schedulers.schedulers:
for scheduler_name in [scheduler.label, scheduler.name, *(scheduler.aliases or [])]:
if name.endswith(" " + scheduler_name):
return name[0:-(len(scheduler_name) + 1)], scheduler_name

return name, "Automatic"


def setUpscalers(req: dict):
reqDict = vars(req)
reqDict['extras_upscaler_1'] = reqDict.pop('upscaler_1', None)
Expand Down Expand Up @@ -447,7 +438,7 @@ def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
self.apply_infotext(txt2imgreq, "txt2img", script_runner=script_runner, mentioned_script_args=infotext_script_args)

selectable_scripts, selectable_script_idx = self.get_selectable_script(txt2imgreq.script_name, script_runner)
sampler, scheduler = parse_old_sampler_name(txt2imgreq.sampler_name or txt2imgreq.sampler_index)
sampler, scheduler = sd_samplers.get_sampler_and_scheduler(txt2imgreq.sampler_name or txt2imgreq.sampler_index, txt2imgreq.scheduler)

populate = txt2imgreq.copy(update={ # Override __init__ params
"sampler_name": validate_sampler_name(sampler),
Expand All @@ -457,7 +448,7 @@ def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
if populate.sampler_name:
populate.sampler_index = None # prevent a warning later on

if not populate.scheduler:
if not populate.scheduler and scheduler != "Automatic":
populate.scheduler = scheduler

args = vars(populate)
Expand Down Expand Up @@ -515,7 +506,7 @@ def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):
self.apply_infotext(img2imgreq, "img2img", script_runner=script_runner, mentioned_script_args=infotext_script_args)

selectable_scripts, selectable_script_idx = self.get_selectable_script(img2imgreq.script_name, script_runner)
sampler, scheduler = parse_old_sampler_name(img2imgreq.sampler_name or img2imgreq.sampler_index)
sampler, scheduler = sd_samplers.get_sampler_and_scheduler(img2imgreq.sampler_name or img2imgreq.sampler_index, img2imgreq.scheduler)

populate = img2imgreq.copy(update={ # Override __init__ params
"sampler_name": validate_sampler_name(sampler),
Expand All @@ -526,7 +517,7 @@ def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):
if populate.sampler_name:
populate.sampler_index = None # prevent a warning later on

if not populate.scheduler:
if not populate.scheduler and scheduler != "Automatic":
populate.scheduler = scheduler

args = vars(populate)
Expand Down

0 comments on commit 4482131

Please sign in to comment.