Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -126,31 +126,6 @@ def calc_emb_cropped(image, app, min_bbox_ratio=0.2):
|
|
126 |
|
127 |
return cropped_face_image
|
128 |
|
129 |
-
def print_tree(root_dir, prefix=""):
|
130 |
-
"""
|
131 |
-
Recursively prints the directory structure starting from `root_dir`.
|
132 |
-
|
133 |
-
Args:
|
134 |
-
root_dir (str): Path to the root directory.
|
135 |
-
prefix (str): Prefix for formatting the tree structure.
|
136 |
-
"""
|
137 |
-
# List all files and directories in the current folder
|
138 |
-
items = os.listdir(root_dir)
|
139 |
-
items.sort() # Sort for consistent output
|
140 |
-
|
141 |
-
for i, item in enumerate(items):
|
142 |
-
path = os.path.join(root_dir, item)
|
143 |
-
is_last = (i == len(items) - 1)
|
144 |
-
|
145 |
-
# Print item name with tree branch
|
146 |
-
print(f"{prefix}{'└── ' if is_last else '├── '}{item}")
|
147 |
-
|
148 |
-
# If the item is a directory, recurse into it
|
149 |
-
if os.path.isdir(path):
|
150 |
-
print_tree(path, prefix + (" " if is_last else "│ "))
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
def make_canny_condition(image, min_val=100, max_val=200, w_bilateral=True):
|
155 |
if w_bilateral:
|
156 |
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
|
@@ -164,42 +139,14 @@ def make_canny_condition(image, min_val=100, max_val=200, w_bilateral=True):
|
|
164 |
image = Image.fromarray(image)
|
165 |
return image
|
166 |
|
|
|
|
|
|
|
|
|
167 |
|
168 |
default_negative_prompt = "Logo,Watermark,Text,Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate,Mutilated,Mutilated hands,Poorly drawn face,Deformed,Bad anatomy,Cloned face,Malformed limbs,Missing legs,Too many fingers"
|
169 |
|
170 |
-
#
|
171 |
-
CURRENT_LORA_NAME = None
|
172 |
-
|
173 |
-
# Load face detection and recognition package
|
174 |
-
# app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
175 |
-
|
176 |
-
|
177 |
-
# # Define your repository, target directory, and local directory
|
178 |
-
# repo_id = "briaai/ID_preservation_2.3"
|
179 |
-
# target_dir = "models_aura/" # The directory you want to download
|
180 |
-
# local_dir = "./checkpoints" # Local directory to save files
|
181 |
-
|
182 |
-
# # Initialize the API
|
183 |
-
# api = HfApi()
|
184 |
-
# # List all files in the repository
|
185 |
-
# files = api.list_repo_files(repo_id=repo_id, repo_type="model") # Use repo_type="space" for Spaces
|
186 |
-
|
187 |
-
# # Filter files that are in the target directory
|
188 |
-
# files_in_dir = [file for file in files if file.startswith(target_dir)]
|
189 |
-
# # Download each file in the target directory
|
190 |
-
# for file in files_in_dir:
|
191 |
-
# local_path = os.path.join(local_dir, file)
|
192 |
-
# os.makedirs(os.path.dirname(local_path), exist_ok=True) # Ensure local directories exist
|
193 |
-
# print(f"Downloading: {file}")
|
194 |
-
# hf_hub_download(repo_id=repo_id, filename=file, local_dir=os.path.dirname(local_path))
|
195 |
-
|
196 |
-
|
197 |
-
# # Local directory where files were downloaded
|
198 |
-
# local_dir = "./checkpoints/models_aura"
|
199 |
-
|
200 |
-
# print(f"Folder structure of '{local_dir}':")
|
201 |
-
# print_tree(local_dir)
|
202 |
-
|
203 |
snapshot_download(
|
204 |
"fal/AuraFace-v1",
|
205 |
local_dir="models/auraface",
|
@@ -211,12 +158,10 @@ app = FaceAnalysis(
|
|
211 |
root=".",
|
212 |
)
|
213 |
|
214 |
-
# app = FaceAnalysis(name='auraface', root='./checkpoints/models_aura/', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
215 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
216 |
|
217 |
|
218 |
# download checkpoints
|
219 |
-
|
220 |
hf_hub_download(repo_id="briaai/ID_preservation_2.3", filename="controlnet/config.json", local_dir="./checkpoints")
|
221 |
hf_hub_download(repo_id="briaai/ID_preservation_2.3", filename="controlnet/diffusion_pytorch_model.safetensors", local_dir="./checkpoints")
|
222 |
hf_hub_download(repo_id="briaai/ID_preservation_2.3", filename="ip-adapter.bin", local_dir="./checkpoints")
|
@@ -229,7 +174,6 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
229 |
# ckpts paths
|
230 |
face_adapter = f"./checkpoints/ip-adapter.bin"
|
231 |
controlnet_path = f"./checkpoints/controlnet"
|
232 |
-
# lora_base_path = "./checkpoints/LoRAs"
|
233 |
base_model_path = f'briaai/BRIA-2.3'
|
234 |
resolution = 1024
|
235 |
|
@@ -261,21 +205,7 @@ pipe.load_ip_adapter_instantid(face_adapter)
|
|
261 |
|
262 |
clip_embeds=None
|
263 |
|
264 |
-
# Loras_dict = {
|
265 |
-
# "":"",
|
266 |
-
# "Vangogh_Vanilla": "bold, dramatic brush strokes, vibrant colors, swirling patterns, intense, emotionally charged paintings of",
|
267 |
-
# "Avatar_internlm": "2d anime sketch avatar of",
|
268 |
-
# "Storyboards": "Illustration style for storyboarding.",
|
269 |
-
# "3D_illustration": "3D object illustration, abstract.",
|
270 |
-
# "Characters": "gaming vector Art."
|
271 |
-
# }
|
272 |
|
273 |
-
# lora_names = Loras_dict.keys()
|
274 |
-
|
275 |
-
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
276 |
-
if randomize_seed:
|
277 |
-
seed = random.randint(0, 99999999)
|
278 |
-
return seed
|
279 |
|
280 |
|
281 |
@spaces.GPU
|
|
|
126 |
|
127 |
return cropped_face_image
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
def make_canny_condition(image, min_val=100, max_val=200, w_bilateral=True):
|
130 |
if w_bilateral:
|
131 |
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
|
|
|
139 |
image = Image.fromarray(image)
|
140 |
return image
|
141 |
|
142 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
143 |
+
if randomize_seed:
|
144 |
+
seed = random.randint(0, 99999999)
|
145 |
+
return seed
|
146 |
|
147 |
default_negative_prompt = "Logo,Watermark,Text,Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate,Mutilated,Mutilated hands,Poorly drawn face,Deformed,Bad anatomy,Cloned face,Malformed limbs,Missing legs,Too many fingers"
|
148 |
|
149 |
+
# Download face encoder
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
snapshot_download(
|
151 |
"fal/AuraFace-v1",
|
152 |
local_dir="models/auraface",
|
|
|
158 |
root=".",
|
159 |
)
|
160 |
|
|
|
161 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
162 |
|
163 |
|
164 |
# download checkpoints
|
|
|
165 |
hf_hub_download(repo_id="briaai/ID_preservation_2.3", filename="controlnet/config.json", local_dir="./checkpoints")
|
166 |
hf_hub_download(repo_id="briaai/ID_preservation_2.3", filename="controlnet/diffusion_pytorch_model.safetensors", local_dir="./checkpoints")
|
167 |
hf_hub_download(repo_id="briaai/ID_preservation_2.3", filename="ip-adapter.bin", local_dir="./checkpoints")
|
|
|
174 |
# ckpts paths
|
175 |
face_adapter = f"./checkpoints/ip-adapter.bin"
|
176 |
controlnet_path = f"./checkpoints/controlnet"
|
|
|
177 |
base_model_path = f'briaai/BRIA-2.3'
|
178 |
resolution = 1024
|
179 |
|
|
|
205 |
|
206 |
clip_embeds=None
|
207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
|
211 |
@spaces.GPU
|