fix: civitai download url

For self hosting instance, this quick fix enable you to have the civitai token appended to the download url.

Add CIVITAI_TOKEN in Fly io
This commit is contained in:
bennykok 2024-01-31 16:33:16 +08:00
parent 774fd566d1
commit 018d9a7b8d
3 changed files with 11 additions and 1 deletions

View File

@ -312,7 +312,8 @@ async def build_logic(item: Item):
config = { config = {
"name": item.name, "name": item.name,
"deploy_test": os.environ.get("DEPLOY_TEST_FLAG", "False"), "deploy_test": os.environ.get("DEPLOY_TEST_FLAG", "False"),
"gpu": item.gpu "gpu": item.gpu,
"civitai_token": os.environ.get("CIVITAI_TOKEN", "")
} }
with open(f"{folder_path}/config.py", "w") as f: with open(f"{folder_path}/config.py", "w") as f:
f.write("config = " + json.dumps(config)) f.write("config = " + json.dumps(config))

View File

@ -36,6 +36,9 @@ if not deploy_test:
dockerfile_image = ( dockerfile_image = (
modal.Image.debian_slim() modal.Image.debian_slim()
.env({
"CIVITAI_TOKEN": config["civitai_token"],
})
.apt_install("git", "wget") .apt_install("git", "wget")
.pip_install( .pip_install(
"git+https://github.com/modal-labs/asgiproxy.git", "httpx", "tqdm" "git+https://github.com/modal-labs/asgiproxy.git", "httpx", "tqdm"

View File

@ -49,6 +49,12 @@ with open('models.json') as f:
models = json.load(f) models = json.load(f)
for model in models: for model in models:
import os
if "civitai.com/api" in model['url'] and not "token=" in model['url']:
if "?" in model['url']:
model['url'] += "&token=" + os.environ.get('CIVITAI_TOKEN', '')
else:
model['url'] += "?token=" + os.environ.get('CIVITAI_TOKEN', '')
response = requests.request("POST", f"{root_url}/model/install", json=model, headers=headers) response = requests.request("POST", f"{root_url}/model/install", json=model, headers=headers)
print(response.text) print(response.text)