diff --git a/README.cn.md b/README.cn.md index b263415..588c36e 100644 --- a/README.cn.md +++ b/README.cn.md @@ -115,10 +115,24 @@ Stable Diffusion Webui 扩展Civitai助手,用于更轻松的管理和使用Ci ## 设置 现在所有设置被移动到 Setting 页面->Civitai Helper区域中。 +### 代理 代理输入框也在其中。 有些sock5代理, 需要使用socks5h开头的形式"socks5h://xxxxx"才能生效。 ![](img/other_setting.jpg) +### Civitai API Key +有些模型现在要登录civitai网站才能下载。要通过Civitai API做到这一点,你需要在你的civitai帐号设置中,创建一个API Key,然后填写到本扩展的设置中来。 + +zixaphir写了一个详细的教程: [wiki](https://github.com/zixaphir/Stable-Diffusion-Webui-Civitai-Helper/wiki/Civitai-API-Key). + +这里是比较简单的教程: +* 登录 civitai.com +* 前往 [你的帐号的Account Setting页面](https://civitai.com/user/account) +* 在页面底部,找到"API Keys"部分. +* 点击"Add API Key"按钮, 起个名字. +* 复制生成的api key字符串,粘贴到本扩展设置页面 -> Civitai API Key 部分. +* 保存设置,并重启SD webui + ## 预览图 Extra Network支持两种预览图命名:`model_name.png` 和 `model_name.preview.png`。其中,`model_name.png`优先级较高。 diff --git a/README.md b/README.md index 301570b..d784768 100644 --- a/README.md +++ b/README.md @@ -125,10 +125,24 @@ After clicking button, extension will download that civitai model's info and pre ## Settings Now all settings are moved into Setting tab->civitai helper section. +### Proxy For some sock5 proxy, need to be used as "socks5h://127.0.0.1:port". ![](img/other_setting.jpg) +### Civitai API Key +You need to login civitai to download some models. To do this with Civitai API, you need to create an API Key in your account settings on Civitai's website. + +zixaphir created a detailed tutorial for this: [wiki](https://github.com/zixaphir/Stable-Diffusion-Webui-Civitai-Helper/wiki/Civitai-API-Key). + +Here is a simple tutorial: +* Login civitai.com +* go to [your account's setting page](https://civitai.com/user/account) +* At the bottom of that page, find the "API Keys" section. +* Click "Add API Key" button, give a name. +* Copy the api key string, paste to this extension's setting page -> Civitai API Key section. +* Save setting and Reload SD webui + ## Preview Image Extra network uses both `model_file.png` and `model_file.preview.png` as preview image. But `model_file.png` has higher priority, because it is created by yourself. @@ -212,6 +226,9 @@ Since v1.5.5, we've already optimized the SHA256 function to the top. So the onl # Change Log +## v1.9.0 +* support civitai API key for downloading. Check document for detail + ## v1.8.3 * fix a bug of removing model when model name has space in it. diff --git a/scripts/ch_lib/downloader.py b/scripts/ch_lib/downloader.py index 9e70942..36d00f9 100644 --- a/scripts/ch_lib/downloader.py +++ b/scripts/ch_lib/downloader.py @@ -88,6 +88,8 @@ def dl(url, folder, filename, filepath): # create header range headers = {'Range': 'bytes=%d-' % downloaded_size} headers['User-Agent'] = util.def_headers['User-Agent'] + if util.civitai_api_key: + headers["Authorization"] = f"Bearer {util.civitai_api_key}" # download with header r = requests.get(url, stream=True, verify=False, headers=headers, proxies=util.proxies) diff --git a/scripts/ch_lib/util.py b/scripts/ch_lib/util.py index d85dcc4..f2f3011 100644 --- a/scripts/ch_lib/util.py +++ b/scripts/ch_lib/util.py @@ -6,13 +6,16 @@ import requests import shutil -version = "1.8.3" +version = "1.9.0" -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_headers = {'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148', + "Authorization": ""} proxies = None +civitai_api_key = "" + # print for debugging def printD(msg): diff --git a/scripts/civitai_helper.py b/scripts/civitai_helper.py index 2b0b6cb..e20abd5 100644 --- a/scripts/civitai_helper.py +++ b/scripts/civitai_helper.py @@ -44,6 +44,7 @@ def on_ui_settings(): shared.opts.add_option("ch_skip_nsfw_preview", shared.OptionInfo(False, "Skip NSFW Preview Images", gr.Checkbox, {"interactive": True}, section=ch_section)) shared.opts.add_option("ch_open_url_with_js", shared.OptionInfo(True, "Open Url At Client Side", gr.Checkbox, {"interactive": True}, section=ch_section)) shared.opts.add_option("ch_proxy", shared.OptionInfo("", "Civitai Helper Proxy", gr.Textbox, {"interactive": True, "lines":1, "info":"format: socks5h://127.0.0.1:port"}, section=ch_section)) + shared.opts.add_option("ch_civiai_api_key", shared.OptionInfo("", "Civitai API Key", gr.Textbox, {"interactive": True, "lines":1, "info":"check doc:https://github.com/zixaphir/Stable-Diffusion-Webui-Civitai-Helper/tree/master#api-key"}, section=ch_section)) def on_ui_tabs(): # init @@ -68,6 +69,7 @@ def on_ui_tabs(): skip_nsfw_preview = shared.opts.data.get("ch_skip_nsfw_preview", False) open_url_with_js = shared.opts.data.get("ch_open_url_with_js", True) proxy = shared.opts.data.get("ch_proxy", "") + civitai_api_key = shared.opts.data.get("ch_civiai_api_key", "") util.printD("Settings:") util.printD("max_size_preview: " + str(max_size_preview)) @@ -75,6 +77,15 @@ def on_ui_tabs(): util.printD("open_url_with_js: " + str(open_url_with_js)) util.printD("proxy: " + str(proxy)) + # set civitai_api_key + has_api_key = False + if civitai_api_key: + has_api_key = True + util.civitai_api_key = civitai_api_key + util.def_headers["Authorization"] = f"Bearer {civitai_api_key}" + + util.printD(f"use civitai api key: {has_api_key}") + # set proxy if proxy: util.proxies = { @@ -82,6 +93,7 @@ def on_ui_tabs(): "https": proxy, } + # ====Event's function==== def scan_model(scan_model_types): return model_action_civitai.scan_model(scan_model_types, max_size_preview, skip_nsfw_preview)