generate api endpoints allow set model

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-08-13 13:49:23 -04:00
parent 0ae24f9916
commit e8002df534
5 changed files with 20 additions and 3 deletions
+2
View File
@@ -111,6 +111,8 @@ SD.Next will warn on startup on unused cache entries that can be removed. Also,
- **API**
- add `/sdapi/v1/checkpoint` POST endpoint to simply load a model
- add `/sdapi/v1/modules` GET endpoint to get info on model components/modules
- all generate endpoints now support `sd_model_checkpoint` parameter
this allows to specify which model to use for generation without needing to use additional endpoints
- **Refactor**
- change default huggingface cache folder from system default to `models/huggingface`
sd.next will warn on startup on unused cache entries
+3
View File
@@ -119,6 +119,9 @@ def process_images(p: StableDiffusionProcessing) -> Processed:
if not hasattr(p.sd_model, 'sd_checkpoint_info'):
shared.log.error('Processing: incomplete model')
return None
if p.abort:
shared.log.debug('Processing: aborted')
return None
if p.scripts is not None and isinstance(p.scripts, scripts_manager.ScriptRunner):
p.scripts.before_process(p)
stored_opts = {}
+12
View File
@@ -15,6 +15,7 @@ debug = shared.log.trace if os.environ.get('SD_PROCESS_DEBUG', None) is not None
@dataclass(repr=False)
class StableDiffusionProcessing:
def __init__(self,
sd_model_checkpoint: str = None, # # used only to set sd_model
sd_model=None, # pylint: disable=unused-argument # local instance of sd_model
# base params
prompt: str = "",
@@ -355,6 +356,17 @@ class StableDiffusionProcessing:
self.prompt_attention_masks = []
self.negative_prompt_attention_mask = []
self.xyz = xyz
self.abort = False
# set model
if sd_model_checkpoint is not None and len(sd_model_checkpoint) > 0:
from modules import sd_checkpoint
if sd_checkpoint.select_checkpoint(op='model', sd_model_checkpoint=sd_model_checkpoint) is None:
shared.log.error(f'Processing: model="{sd_model_checkpoint}" not found')
self.abort = True
else:
shared.opts.sd_model_checkpoint = sd_model_checkpoint
sd_models.reload_model_weights()
def __str__(self):
return f'{self.__class__.__name__}: {self.__dict__}'
+2 -2
View File
@@ -269,8 +269,8 @@ def model_hash(filename):
return 'NOHASH'
def select_checkpoint(op='model'):
model_checkpoint = shared.opts.data.get('sd_model_refiner', None) if op == 'refiner' else shared.opts.data.get('sd_model_checkpoint', None)
def select_checkpoint(op='model', sd_model_checkpoint=None):
model_checkpoint = sd_model_checkpoint or (shared.opts.data.get('sd_model_refiner', None) if op == 'refiner' else shared.opts.data.get('sd_model_checkpoint', None))
if model_checkpoint is None or model_checkpoint == 'None' or len(model_checkpoint) < 3:
return None
checkpoint_info = get_closet_checkpoint_match(model_checkpoint)