Spaces:
Build error
Build error
Jordan Schalter
commited on
Commit
•
4830dc6
1
Parent(s):
553ba0e
Add application file
Browse files- Dockerfile +29 -0
- app.py +147 -0
- requirements.txt +24 -0
Dockerfile
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM nvidia/cuda:12.4.1-base-ubuntu22.04
|
2 |
+
ENV DEBIAN_FRONTEND noninteractive
|
3 |
+
ENV CMDARGS --listen
|
4 |
+
|
5 |
+
RUN apt-get update -y && \
|
6 |
+
apt-get install -y curl libgl1 libglib2.0-0 python3-pip python-is-python3 git && \
|
7 |
+
apt-get clean && \
|
8 |
+
rm -rf /var/lib/apt/lists/*
|
9 |
+
|
10 |
+
COPY requirements_docker.txt requirements_versions.txt /tmp/
|
11 |
+
RUN pip install --no-cache-dir -r /tmp/requirements_docker.txt -r /tmp/requirements_versions.txt && \
|
12 |
+
rm -f /tmp/requirements_docker.txt /tmp/requirements_versions.txt
|
13 |
+
RUN pip install --no-cache-dir xformers==0.0.23 --no-dependencies
|
14 |
+
RUN curl -fsL -o /usr/local/lib/python3.10/dist-packages/gradio/frpc_linux_amd64_v0.2 https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_linux_amd64 && \
|
15 |
+
chmod +x /usr/local/lib/python3.10/dist-packages/gradio/frpc_linux_amd64_v0.2
|
16 |
+
|
17 |
+
RUN adduser --disabled-password --gecos '' user && \
|
18 |
+
mkdir -p /content/app /content/data
|
19 |
+
|
20 |
+
COPY entrypoint.sh /content/
|
21 |
+
RUN chown -R user:user /content
|
22 |
+
|
23 |
+
WORKDIR /content
|
24 |
+
USER user
|
25 |
+
|
26 |
+
COPY --chown=user:user . /content/app
|
27 |
+
RUN mv /content/app/models /content/app/models.org
|
28 |
+
|
29 |
+
CMD [ "sh", "-c", "/content/entrypoint.sh ${CMDARGS}" ]
|
app.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import ssl
|
3 |
+
import sys
|
4 |
+
|
5 |
+
print('[System ARGV] ' + str(sys.argv))
|
6 |
+
|
7 |
+
root = os.path.dirname(os.path.abspath(__file__))
|
8 |
+
sys.path.append(root)
|
9 |
+
os.chdir(root)
|
10 |
+
|
11 |
+
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
12 |
+
os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"
|
13 |
+
if "GRADIO_SERVER_PORT" not in os.environ:
|
14 |
+
os.environ["GRADIO_SERVER_PORT"] = "7865"
|
15 |
+
|
16 |
+
ssl._create_default_https_context = ssl._create_unverified_context
|
17 |
+
|
18 |
+
import platform
|
19 |
+
import fooocus_version
|
20 |
+
|
21 |
+
from build_launcher import build_launcher
|
22 |
+
from modules.launch_util import is_installed, run, python, run_pip, requirements_met, delete_folder_content
|
23 |
+
from modules.model_loader import load_file_from_url
|
24 |
+
|
25 |
+
REINSTALL_ALL = False
|
26 |
+
TRY_INSTALL_XFORMERS = False
|
27 |
+
|
28 |
+
|
29 |
+
def prepare_environment():
|
30 |
+
torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu121")
|
31 |
+
torch_command = os.environ.get('TORCH_COMMAND',
|
32 |
+
f"pip install torch==2.1.0 torchvision==0.16.0 --extra-index-url {torch_index_url}")
|
33 |
+
requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
|
34 |
+
|
35 |
+
print(f"Python {sys.version}")
|
36 |
+
print(f"Fooocus version: {fooocus_version.version}")
|
37 |
+
|
38 |
+
if REINSTALL_ALL or not is_installed("torch") or not is_installed("torchvision"):
|
39 |
+
run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
|
40 |
+
|
41 |
+
if TRY_INSTALL_XFORMERS:
|
42 |
+
if REINSTALL_ALL or not is_installed("xformers"):
|
43 |
+
xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.23')
|
44 |
+
if platform.system() == "Windows":
|
45 |
+
if platform.python_version().startswith("3.10"):
|
46 |
+
run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True)
|
47 |
+
else:
|
48 |
+
print("Installation of xformers is not supported in this version of Python.")
|
49 |
+
print(
|
50 |
+
"You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
|
51 |
+
if not is_installed("xformers"):
|
52 |
+
exit(0)
|
53 |
+
elif platform.system() == "Linux":
|
54 |
+
run_pip(f"install -U -I --no-deps {xformers_package}", "xformers")
|
55 |
+
|
56 |
+
if REINSTALL_ALL or not requirements_met(requirements_file):
|
57 |
+
run_pip(f"install -r \"{requirements_file}\"", "requirements")
|
58 |
+
|
59 |
+
return
|
60 |
+
|
61 |
+
|
62 |
+
vae_approx_filenames = [
|
63 |
+
('xlvaeapp.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/xlvaeapp.pth'),
|
64 |
+
('vaeapp_sd15.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/vaeapp_sd15.pt'),
|
65 |
+
('xl-to-v1_interposer-v4.0.safetensors',
|
66 |
+
'https://huggingface.co/mashb1t/misc/resolve/main/xl-to-v1_interposer-v4.0.safetensors')
|
67 |
+
]
|
68 |
+
|
69 |
+
|
70 |
+
def ini_args():
|
71 |
+
from args_manager import args
|
72 |
+
return args
|
73 |
+
|
74 |
+
|
75 |
+
prepare_environment()
|
76 |
+
build_launcher()
|
77 |
+
args = ini_args()
|
78 |
+
|
79 |
+
if args.gpu_device_id is not None:
|
80 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = str(args.gpu_device_id)
|
81 |
+
print("Set device to:", args.gpu_device_id)
|
82 |
+
|
83 |
+
if args.hf_mirror is not None :
|
84 |
+
os.environ['HF_MIRROR'] = str(args.hf_mirror)
|
85 |
+
print("Set hf_mirror to:", args.hf_mirror)
|
86 |
+
|
87 |
+
from modules import config
|
88 |
+
from modules.hash_cache import init_cache
|
89 |
+
os.environ["U2NET_HOME"] = config.path_inpaint
|
90 |
+
|
91 |
+
os.environ['GRADIO_TEMP_DIR'] = config.temp_path
|
92 |
+
|
93 |
+
if config.temp_path_cleanup_on_launch:
|
94 |
+
print(f'[Cleanup] Attempting to delete content of temp dir {config.temp_path}')
|
95 |
+
result = delete_folder_content(config.temp_path, '[Cleanup] ')
|
96 |
+
if result:
|
97 |
+
print("[Cleanup] Cleanup successful")
|
98 |
+
else:
|
99 |
+
print(f"[Cleanup] Failed to delete content of temp dir.")
|
100 |
+
|
101 |
+
|
102 |
+
def download_models(default_model, previous_default_models, checkpoint_downloads, embeddings_downloads, lora_downloads, vae_downloads):
|
103 |
+
for file_name, url in vae_approx_filenames:
|
104 |
+
load_file_from_url(url=url, model_dir=config.path_vae_approx, file_name=file_name)
|
105 |
+
|
106 |
+
load_file_from_url(
|
107 |
+
url='https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin',
|
108 |
+
model_dir=config.path_fooocus_expansion,
|
109 |
+
file_name='pytorch_model.bin'
|
110 |
+
)
|
111 |
+
|
112 |
+
if args.disable_preset_download:
|
113 |
+
print('Skipped model download.')
|
114 |
+
return default_model, checkpoint_downloads
|
115 |
+
|
116 |
+
if not args.always_download_new_model:
|
117 |
+
if not os.path.exists(os.path.join(config.paths_checkpoints[0], default_model)):
|
118 |
+
for alternative_model_name in previous_default_models:
|
119 |
+
if os.path.exists(os.path.join(config.paths_checkpoints[0], alternative_model_name)):
|
120 |
+
print(f'You do not have [{default_model}] but you have [{alternative_model_name}].')
|
121 |
+
print(f'Fooocus will use [{alternative_model_name}] to avoid downloading new models, '
|
122 |
+
f'but you are not using the latest models.')
|
123 |
+
print('Use --always-download-new-model to avoid fallback and always get new models.')
|
124 |
+
checkpoint_downloads = {}
|
125 |
+
default_model = alternative_model_name
|
126 |
+
break
|
127 |
+
|
128 |
+
for file_name, url in checkpoint_downloads.items():
|
129 |
+
load_file_from_url(url=url, model_dir=config.paths_checkpoints[0], file_name=file_name)
|
130 |
+
for file_name, url in embeddings_downloads.items():
|
131 |
+
load_file_from_url(url=url, model_dir=config.path_embeddings, file_name=file_name)
|
132 |
+
for file_name, url in lora_downloads.items():
|
133 |
+
load_file_from_url(url=url, model_dir=config.paths_loras[0], file_name=file_name)
|
134 |
+
for file_name, url in vae_downloads.items():
|
135 |
+
load_file_from_url(url=url, model_dir=config.path_vae, file_name=file_name)
|
136 |
+
|
137 |
+
return default_model, checkpoint_downloads
|
138 |
+
|
139 |
+
|
140 |
+
config.default_base_model_name, config.checkpoint_downloads = download_models(
|
141 |
+
config.default_base_model_name, config.previous_default_models, config.checkpoint_downloads,
|
142 |
+
config.embeddings_downloads, config.lora_downloads, config.vae_downloads)
|
143 |
+
|
144 |
+
config.update_files()
|
145 |
+
init_cache(config.model_filenames, config.paths_checkpoints, config.lora_filenames, config.paths_loras)
|
146 |
+
|
147 |
+
from webui import *
|
requirements.txt
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torchsde==0.2.6
|
2 |
+
einops==0.8.0
|
3 |
+
transformers==4.42.4
|
4 |
+
safetensors==0.4.3
|
5 |
+
accelerate==0.32.1
|
6 |
+
pyyaml==6.0.1
|
7 |
+
pillow==10.4.0
|
8 |
+
scipy==1.14.0
|
9 |
+
tqdm==4.66.4
|
10 |
+
psutil==6.0.0
|
11 |
+
pytorch_lightning==2.3.3
|
12 |
+
omegaconf==2.3.0
|
13 |
+
gradio==3.41.2
|
14 |
+
pygit2==1.15.1
|
15 |
+
opencv-contrib-python-headless==4.10.0.84
|
16 |
+
httpx==0.27.0
|
17 |
+
onnxruntime==1.18.1
|
18 |
+
timm==1.0.7
|
19 |
+
numpy==1.26.4
|
20 |
+
tokenizers==0.19.1
|
21 |
+
packaging==24.1
|
22 |
+
rembg==2.0.57
|
23 |
+
groundingdino-py==0.4.0
|
24 |
+
segment_anything==1.0
|