diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cf66db3a..c1e4950d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Change Log for SD.Next -## Update for 2025-05-06 +## Update for 2025-05-07 +- **API** + - full API support for FramePack + - add `/sdapi/v1/checkpoint` endpoint to get info on currently loaded model/checkpoint - **Fixes** - FramePack: monkey-patch for dynamically installed `av` - Logging: reduce spam while progress is active diff --git a/cli/api-checkpoint.py b/cli/api-checkpoint.py new file mode 100755 index 000000000..61f4e4370 --- /dev/null +++ b/cli/api-checkpoint.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +import os +import logging +import requests +import urllib3 + + +sd_url = os.environ.get('SDAPI_URL', "http://127.0.0.1:7860") +sd_username = os.environ.get('SDAPI_USR', None) +sd_password = os.environ.get('SDAPI_PWD', None) +options = { + "save_images": True, + "send_images": True, +} + +logging.basicConfig(level = logging.INFO, format = '%(asctime)s %(levelname)s: %(message)s') +log = logging.getLogger(__name__) +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + + +def auth(): + if sd_username is not None and sd_password is not None: + return requests.auth.HTTPBasicAuth(sd_username, sd_password) + return None + + +def get(endpoint: str, dct: dict = None): + req = requests.get(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth()) + if req.status_code != 200: + return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } + else: + return req.json() + + +if __name__ == "__main__": + model = get('/sdapi/v1/checkpoint') + log.info(f'api-checkpoint: {model}') diff --git a/modules/api/api.py b/modules/api/api.py index 39210ffca..b653250f5 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -89,6 +89,7 @@ class Api: self.add_api_route("/sdapi/v1/png-info", endpoints.post_pnginfo, methods=["POST"], response_model=models.ResImageInfo) self.add_api_route("/sdapi/v1/interrogate", endpoints.post_interrogate, methods=["POST"]) self.add_api_route("/sdapi/v1/vqa", endpoints.post_vqa, methods=["POST"]) + self.add_api_route("/sdapi/v1/checkpoint", endpoints.get_checkpoint, methods=["GET"]) self.add_api_route("/sdapi/v1/refresh-checkpoints", endpoints.post_refresh_checkpoints, methods=["POST"]) self.add_api_route("/sdapi/v1/unload-checkpoint", endpoints.post_unload_checkpoint, methods=["POST"]) self.add_api_route("/sdapi/v1/reload-checkpoint", endpoints.post_reload_checkpoint, methods=["POST"]) diff --git a/modules/api/endpoints.py b/modules/api/endpoints.py index 1decd8c71..80b46f324 100644 --- a/modules/api/endpoints.py +++ b/modules/api/endpoints.py @@ -130,6 +130,26 @@ def post_reload_checkpoint(): sd_models.reload_model_weights() return {} +def get_checkpoint(): + if not shared.sd_loaded or shared.sd_model is None: + checkpoint = { + 'type': None, + 'class': None, + } + else: + checkpoint = { + 'type': shared.sd_model_type, + 'class': shared.sd_model.__class__.__name__, + } + if hasattr(shared.sd_model, 'sd_model_checkpoint'): + checkpoint['checkpoint'] = shared.sd_model.sd_model_checkpoint + if hasattr(shared.sd_model, 'sd_checkpoint_info'): + checkpoint['title'] = shared.sd_model.sd_checkpoint_info.title + checkpoint['name'] = shared.sd_model.sd_checkpoint_info.name + checkpoint['filename'] = shared.sd_model.sd_checkpoint_info.filename + checkpoint['hash'] = shared.sd_model.sd_checkpoint_info.shorthash + return checkpoint + def post_refresh_checkpoints(): shared.refresh_checkpoints() return {}