Skip to content

Instantly share code, notes, and snippets.

@ouor
Last active February 6, 2023 09:41
Show Gist options
  • Save ouor/f4b0b7624c397c5c555e967a3d3bd02d to your computer and use it in GitHub Desktop.
Save ouor/f4b0b7624c397c5c555e967a3d3bd02d to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "8d1a23d6-b2c6-4141-ad22-6f63127c30cc",
"metadata": {},
"source": [
"모델 다운받기"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ebca98eb-7a3e-4304-994f-cf74fe725f44",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"home_dir = os.getcwd()\n",
"repo_dir = os.path.join(home_dir, 'stable-diffusion-webui')\n",
"os.chdir(repo_dir)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "49b8c19c-f33b-4ec7-b890-5c4be4aa0567",
"metadata": {},
"outputs": [],
"source": [
"# 원래 있는 sd 모델 삭제\n",
"for i in [x for x in os.listdir(home_dir) if x.endswith('.ckpt')]:\n",
" os.remove(os.path.join(home_dir, i))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "41c4f308-b68a-46b3-8ae7-1c7d46c981e4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2023-02-06 09:16:04-- https://huggingface.co/syaimu/7th_Layer/resolve/main/7th_anime_v3/7th_anime_v3_A.safetensors\n",
"Resolving huggingface.co (huggingface.co)... 3.231.67.228, 54.235.118.239, 2600:1f18:147f:e800:671:b733:ecf3:a585, ...\n",
"Connecting to huggingface.co (huggingface.co)|3.231.67.228|:443... connected.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://cdn-lfs.huggingface.co/repos/0c/8c/0c8c3a139a854a317f227f1f1c2f695f4e7f15fa728359e39f1b6085d4c23d36/c330a60ddcb49c61109dbd7c28cf326733dadb77984c6e8d162bdc200a05df9e?response-content-disposition=attachment%3B+filename*%3DUTF-8%27%277th_anime_v3_A.safetensors%3B+filename%3D%227th_anime_v3_A.safetensors%22%3B&Expires=1675933915&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9jZG4tbGZzLmh1Z2dpbmdmYWNlLmNvL3JlcG9zLzBjLzhjLzBjOGMzYTEzOWE4NTRhMzE3ZjIyN2YxZjFjMmY2OTVmNGU3ZjE1ZmE3MjgzNTllMzlmMWI2MDg1ZDRjMjNkMzYvYzMzMGE2MGRkY2I0OWM2MTEwOWRiZDdjMjhjZjMyNjczM2RhZGI3Nzk4NGM2ZThkMTYyYmRjMjAwYTA1ZGY5ZT9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE2NzU5MzM5MTV9fX1dfQ__&Signature=WLQ4Kifv-3QwBHonSdrZOx7Ef0Z0iyV6danwso-DE2jaEj7JckLyYtMjhTLbjAHhULHsx-MZTrqnWFweXxg2%7E0Qg0zKwcA-UNYGcsPisO8jr2CHLkWvEhcB53cBZhSYktnzOKHt75M837DG6-IyDePIYjlSLcYRTQRRPWM3WrQB2GkRGUVdo6tfOW4wOBld%7ELB2FE--NIABzhm0WJoCQ-%7E23QYayFAn%7ELB5yZJvbBTcKiJmljZg8BRhwVrEsIWjVdRrna4yl3TXe6Dv-qCjJvtu%7Eit9BehWAjmhCCN1jsiowo51UcOeElvGuVz9gs-c4XAOv8ZH2GBYzPkNHvsBFAg__&Key-Pair-Id=KVTP0A1DKRTAX [following]\n",
"--2023-02-06 09:16:05-- https://cdn-lfs.huggingface.co/repos/0c/8c/0c8c3a139a854a317f227f1f1c2f695f4e7f15fa728359e39f1b6085d4c23d36/c330a60ddcb49c61109dbd7c28cf326733dadb77984c6e8d162bdc200a05df9e?response-content-disposition=attachment%3B+filename*%3DUTF-8%27%277th_anime_v3_A.safetensors%3B+filename%3D%227th_anime_v3_A.safetensors%22%3B&Expires=1675933915&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9jZG4tbGZzLmh1Z2dpbmdmYWNlLmNvL3JlcG9zLzBjLzhjLzBjOGMzYTEzOWE4NTRhMzE3ZjIyN2YxZjFjMmY2OTVmNGU3ZjE1ZmE3MjgzNTllMzlmMWI2MDg1ZDRjMjNkMzYvYzMzMGE2MGRkY2I0OWM2MTEwOWRiZDdjMjhjZjMyNjczM2RhZGI3Nzk4NGM2ZThkMTYyYmRjMjAwYTA1ZGY5ZT9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE2NzU5MzM5MTV9fX1dfQ__&Signature=WLQ4Kifv-3QwBHonSdrZOx7Ef0Z0iyV6danwso-DE2jaEj7JckLyYtMjhTLbjAHhULHsx-MZTrqnWFweXxg2%7E0Qg0zKwcA-UNYGcsPisO8jr2CHLkWvEhcB53cBZhSYktnzOKHt75M837DG6-IyDePIYjlSLcYRTQRRPWM3WrQB2GkRGUVdo6tfOW4wOBld%7ELB2FE--NIABzhm0WJoCQ-%7E23QYayFAn%7ELB5yZJvbBTcKiJmljZg8BRhwVrEsIWjVdRrna4yl3TXe6Dv-qCjJvtu%7Eit9BehWAjmhCCN1jsiowo51UcOeElvGuVz9gs-c4XAOv8ZH2GBYzPkNHvsBFAg__&Key-Pair-Id=KVTP0A1DKRTAX\n",
"Resolving cdn-lfs.huggingface.co (cdn-lfs.huggingface.co)... 99.86.63.67, 99.86.63.91, 99.86.63.37, ...\n",
"Connecting to cdn-lfs.huggingface.co (cdn-lfs.huggingface.co)|99.86.63.67|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 4265096689 (4.0G) [binary/octet-stream]\n",
"Saving to: ‘/workspace/stable-diffusion-webui/models/Stable-diffusion/7th_anime_v3_A.safetensors’\n",
"\n",
"7th_anime_v3_A.safe 100%[===================>] 3.97G 189MB/s in 23s \n",
"\n",
"2023-02-06 09:16:28 (174 MB/s) - ‘/workspace/stable-diffusion-webui/models/Stable-diffusion/7th_anime_v3_A.safetensors’ saved [4265096689/4265096689]\n",
"\n"
]
}
],
"source": [
"# 모델 다운로드\n",
"model_url = 'https://huggingface.co/syaimu/7th_Layer/resolve/main/7th_anime_v3/7th_anime_v3_A.safetensors'\n",
"\n",
"models_dir = os.path.join(repo_dir, 'models', 'Stable-diffusion')\n",
"! wget {model_url} -P {models_dir}"
]
},
{
"cell_type": "markdown",
"id": "9c57c2a6-b899-4622-a96a-cd350859f74a",
"metadata": {},
"source": [
"인퍼런스 제한 걸기"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1da6767f-3825-4fc8-8a50-d57f3d6b5247",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import shutil"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "64427a9d-8867-4cd2-be07-44a1dc0fca80",
"metadata": {},
"outputs": [],
"source": [
"ui_conf_path = os.path.join(repo_dir, 'ui-config.json')\n",
"ui_conf_bk_path = os.path.join(repo_dir, 'ui-config_bk.json')\n",
"shutil.copy(ui_conf_path, ui_conf_bk_path)\n",
"with open(ui_conf_path, 'r', encoding='utf-8') as f:\n",
" orig_ui = json.load(f)\n",
" ur_ui = orig_ui"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "517d51a1-b407-4243-9e3e-6e65f60bc3f2",
"metadata": {},
"outputs": [],
"source": [
"for k, v in orig_ui.items():\n",
" if k.startswith('txt2img') or k.startswith('img2img'):\n",
" print(f'{k}: {v}')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "65b129af-914d-4731-99a8-eeeeac877821",
"metadata": {},
"outputs": [],
"source": [
"# 변수 편집\n",
"\n",
"method = False # 샘플링 메소드 변경 못하게\n",
"step_limit = 30 # 최대 스텝 제한\n",
"width = 768 # 이미지 가로폭 제한\n",
"height = 768 # 이미지 세로폭 제한\n",
"cfg = 15 # CFG 스케일 제한\n",
"batch = False # 배치 기능 사용 못하게\n",
"script = False # xy plot 같은 스크립트 사용 못하게\n",
"\n",
"ur_ui['txt2img/Sampling method/visible'] = method\n",
"ur_ui['txt2img/Sampling steps/maximum'] = step_limit\n",
"ur_ui['txt2img/Width/maximum'] = width\n",
"ur_ui['txt2img/Height/maximum'] = height\n",
"ur_ui['txt2img/CFG Scale/maximum'] = cfg\n",
"ur_ui['txt2img/Batch count/visible'] = batch\n",
"ur_ui['txt2img/Batch size/visible'] = batch\n",
"ur_ui['txt2img/Resize seed from width/maximum'] = width\n",
"ur_ui['txt2img/Resize seed from height/maximum'] = height\n",
"ur_ui['txt2img/Script/visible'] = script\n",
"\n",
"ur_ui['img2img/Sampling method/visible'] = method\n",
"ur_ui['img2img/Sampling steps/maximum'] = step_limit\n",
"ur_ui['img2img/Width/maximum'] = width\n",
"ur_ui['img2img/Height/maximum'] = height\n",
"ur_ui['img2img/CFG Scale/maximum'] = cfg\n",
"ur_ui['img2img/Batch count/visible'] = batch\n",
"ur_ui['img2img/Batch size/visible'] = batch\n",
"ur_ui['img2img/Resize seed from width/maximum'] = width\n",
"ur_ui['img2img/Resize seed from height/maximum'] = height\n",
"ur_ui['img2img/Script/visible'] = script"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f2008767-c8d9-4388-910d-f4f617295631",
"metadata": {},
"outputs": [],
"source": [
"with open(ui_conf_path, 'w', encoding='utf-8') as f:\n",
" json.dump(ur_ui, f, indent=4)"
]
},
{
"cell_type": "markdown",
"id": "19046edc-5278-4740-b2fa-25a69a4ea6b1",
"metadata": {},
"source": [
"탭 없에기"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "867a29b5-7616-406c-baf2-c8b348b0c263",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/workspace/stable-diffusion-webui/modules/ui_bk.py'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ui_py_path = os.path.join(repo_dir, 'modules', 'ui.py')\n",
"ui_py_bk_path = os.path.join(repo_dir, 'modules', 'ui_bk.py')\n",
"shutil.copy(ui_py_path, ui_py_bk_path)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "5d83d79b-0ef5-4f37-8d24-c07967336d5c",
"metadata": {},
"outputs": [],
"source": [
"! sed -i '/extras_interface, \"Extras\", \"extras\"/s/^/#/' {ui_py_path}\n",
"! sed -i '/modelmerger_interface, \"Checkpoint Merger\", \"modelmerger\"/s/^/#/' {ui_py_path}\n",
"! sed -i '/train_interface, \"Train\", \"ti\"/s/^/#/' {ui_py_path}\n",
"! sed -i '/interfaces +=/s/^/#/' {ui_py_path}"
]
},
{
"cell_type": "markdown",
"id": "50177d22-e708-4c72-ba3d-54029a77e014",
"metadata": {},
"source": [
" 모두 끝났습니다. 이제 UI를 리로드 하고 주소를 공유하세요."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ee50a38b",
"metadata": {},
"outputs": [],
"source": [
"# 그런데 원래 UI로 돌아가고 싶으면..\n",
"! cp {ui_py_bk_path} {ui_py_path}\n",
"# 그리고 서버를 껐다가 켭니다"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment