Set API keys for Civitai & HuggingFace in server_settings.yaml.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -159,3 +159,4 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
ui_settings.yaml
|
ui_settings.yaml
|
||||||
|
server_settings.yaml
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ Currently it is still missing some features it should have.
|
|||||||
- Increased supported preview image types.
|
- Increased supported preview image types.
|
||||||
- Correctly change colors using ComfyUI's theme colors.
|
- Correctly change colors using ComfyUI's theme colors.
|
||||||
- Simplified UI.
|
- Simplified UI.
|
||||||
- Settings tab and config file.
|
- Civitai and HuggingFace API token configurable in `server_settings.yaml`.
|
||||||
|
- Settings tab saved in `ui_settings.yaml`.
|
||||||
- Hide/Show 'add' and 'copy-to-clipboard' buttons.
|
- Hide/Show 'add' and 'copy-to-clipboard' buttons.
|
||||||
- Text to always search.
|
- Text to always search.
|
||||||
- Show/Hide add embedding extension.
|
- Show/Hide add embedding extension.
|
||||||
@@ -65,8 +66,6 @@ Currently it is still missing some features it should have.
|
|||||||
- ☐ Check search code is optimized to avoid recalculation on every minor input change
|
- ☐ Check search code is optimized to avoid recalculation on every minor input change
|
||||||
- ☐ Directory dropdown
|
- ☐ Directory dropdown
|
||||||
- ☐ Use always filter to filter directory content auto-suggest dropdown
|
- ☐ Use always filter to filter directory content auto-suggest dropdown
|
||||||
- ☐ Generalize model list filtering code to reuse approach
|
|
||||||
- ☐ Generalize search dropdown for download location selection
|
|
||||||
- ☐ Filters dropdown
|
- ☐ Filters dropdown
|
||||||
- ☐ Stable Diffusion model version/Clip/Upscale/?
|
- ☐ Stable Diffusion model version/Clip/Upscale/?
|
||||||
- ☐ Favorites
|
- ☐ Favorites
|
||||||
|
|||||||
34
__init__.py
34
__init__.py
@@ -28,6 +28,7 @@ index_uri = os.path.join(extension_uri, "index.json")
|
|||||||
#checksum_cache_uri = os.path.join(extension_uri, "checksum_cache.txt")
|
#checksum_cache_uri = os.path.join(extension_uri, "checksum_cache.txt")
|
||||||
no_preview_image = os.path.join(extension_uri, "no-preview.png")
|
no_preview_image = os.path.join(extension_uri, "no-preview.png")
|
||||||
ui_settings_uri = os.path.join(extension_uri, "ui_settings.yaml")
|
ui_settings_uri = os.path.join(extension_uri, "ui_settings.yaml")
|
||||||
|
server_settings_uri = os.path.join(extension_uri, "server_settings.yaml")
|
||||||
|
|
||||||
fallback_model_extensions = set([".bin", ".ckpt", ".onnx", ".pt", ".pth", ".safetensors"]) # TODO: magic values
|
fallback_model_extensions = set([".bin", ".ckpt", ".onnx", ".pt", ".pth", ".safetensors"]) # TODO: magic values
|
||||||
image_extensions = (".apng", ".gif", ".jpeg", ".jpg", ".png", ".webp")
|
image_extensions = (".apng", ".gif", ".jpeg", ".jpg", ".png", ".webp")
|
||||||
@@ -122,13 +123,15 @@ def ui_rules():
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
#def server_rules():
|
def server_rules():
|
||||||
# Rule = config_loader.Rule
|
Rule = config_loader.Rule
|
||||||
# return [
|
return [
|
||||||
# Rule("model_extension_download_whitelist", [".safetensors"], list),
|
#Rule("model_extension_download_whitelist", [".safetensors"], list),
|
||||||
# Rule("civitai_api_key", "", str),
|
Rule("civitai_api_key", "", str),
|
||||||
# ]
|
Rule("huggingface_api_key", "", str),
|
||||||
|
]
|
||||||
|
server_settings = config_loader.yaml_load(server_settings_uri, server_rules())
|
||||||
|
config_loader.yaml_save(server_settings_uri, server_rules(), server_settings)
|
||||||
|
|
||||||
@server.PromptServer.instance.routes.get("/model-manager/settings/load")
|
@server.PromptServer.instance.routes.get("/model-manager/settings/load")
|
||||||
async def load_ui_settings(request):
|
async def load_ui_settings(request):
|
||||||
@@ -384,11 +387,6 @@ async def directory_list(request):
|
|||||||
return web.json_response(dir_list)
|
return web.json_response(dir_list)
|
||||||
|
|
||||||
|
|
||||||
def_headers = {
|
|
||||||
"User-Agent": "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def download_file(url, filename, overwrite):
|
def download_file(url, filename, overwrite):
|
||||||
if not overwrite and os.path.isfile(filename):
|
if not overwrite and os.path.isfile(filename):
|
||||||
raise Exception("File already exists!")
|
raise Exception("File already exists!")
|
||||||
@@ -396,6 +394,18 @@ def download_file(url, filename, overwrite):
|
|||||||
# TODO: clear any previous failed partial download file
|
# TODO: clear any previous failed partial download file
|
||||||
dl_filename = filename + ".download"
|
dl_filename = filename + ".download"
|
||||||
|
|
||||||
|
def_headers = {
|
||||||
|
"User-Agent": "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148",
|
||||||
|
}
|
||||||
|
if url.startswith("https://civitai.com/"):
|
||||||
|
api_key = server_settings["civitai_api_key"]
|
||||||
|
if (api_key != ""):
|
||||||
|
def_headers["Authorization"] = f"Bearer {api_key}"
|
||||||
|
elif url.startswith("https://huggingface.co/"):
|
||||||
|
api_key = server_settings["huggingface_api_key"]
|
||||||
|
if api_key != "":
|
||||||
|
def_headers["Authorization"] = f"Bearer {api_key}"
|
||||||
|
|
||||||
rh = requests.get(url=url, stream=True, verify=False, headers=def_headers, proxies=None, allow_redirects=False)
|
rh = requests.get(url=url, stream=True, verify=False, headers=def_headers, proxies=None, allow_redirects=False)
|
||||||
if not rh.ok:
|
if not rh.ok:
|
||||||
raise Exception("Unable to download")
|
raise Exception("Unable to download")
|
||||||
|
|||||||
@@ -2009,6 +2009,7 @@ class ModelManager extends ComfyDialog {
|
|||||||
record["type"] = els.modelTypeSelect.value;
|
record["type"] = els.modelTypeSelect.value;
|
||||||
if (record["type"] === "") { return; } // TODO: notify user in app
|
if (record["type"] === "") { return; } // TODO: notify user in app
|
||||||
record["path"] = els.saveDirectoryPath.value;
|
record["path"] = els.saveDirectoryPath.value;
|
||||||
|
if (record["path"] === "/") { return; } // TODO: notify user in app
|
||||||
record["name"] = (() => {
|
record["name"] = (() => {
|
||||||
const filename = info["fileName"];
|
const filename = info["fileName"];
|
||||||
const name = els.filename.value;
|
const name = els.filename.value;
|
||||||
|
|||||||
Reference in New Issue
Block a user