Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,10 @@ from face_swapper import Inswapper, paste_to_whole
|
|
10 |
from face_analyser import analyse_face
|
11 |
from face_enhancer import load_face_enhancer_model, get_available_enhancer_names
|
12 |
import tempfile
|
13 |
-
from huggingface_hub import login, hf_hub_download, upload_file, HfApi
|
14 |
from datetime import datetime
|
|
|
|
|
15 |
|
16 |
# --- Config ---
|
17 |
REPO_ID = os.environ.get("HFPATH")
|
@@ -47,6 +49,19 @@ def upload_to_hf(filepath):
|
|
47 |
repo_type="dataset"
|
48 |
)
|
49 |
return f"https://huggingface.co/datasets/{REPO_ID}/blob/main/{path_in_repo}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
# ------------------------------ ARGS ------------------------------
|
51 |
parser = argparse.ArgumentParser(description="Face Swapper (Multi-target, Male+Female Sources)")
|
52 |
parser.add_argument("--out_dir", default=os.getcwd())
|
@@ -166,7 +181,27 @@ def swap_faces(target_files, male_file, female_file, enhancer_name="NONE"):
|
|
166 |
output_path = temp_file.name
|
167 |
cv2.imwrite(output_path, out_frame) # Convert BGR to RGB before saving
|
168 |
output_files.append(output_path)
|
169 |
-
upload_to_hf(output_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
print(f"✔ Hoàn tất tất cả trong {time.time() - start_time:.2f}s")
|
171 |
return output_files
|
172 |
|
|
|
10 |
from face_analyser import analyse_face
|
11 |
from face_enhancer import load_face_enhancer_model, get_available_enhancer_names
|
12 |
import tempfile
|
13 |
+
from huggingface_hub import login, hf_hub_download, upload_file, HfApi,upload_folder
|
14 |
from datetime import datetime
|
15 |
+
import shutil
|
16 |
+
|
17 |
|
18 |
# --- Config ---
|
19 |
REPO_ID = os.environ.get("HFPATH")
|
|
|
49 |
repo_type="dataset"
|
50 |
)
|
51 |
return f"https://huggingface.co/datasets/{REPO_ID}/blob/main/{path_in_repo}"
|
52 |
+
# --- Upload function ---
|
53 |
+
def upload_to_fd(path):
|
54 |
+
#filename = os.path.basename(filepath)
|
55 |
+
SUBFOLDER = datetime.now().strftime("%Y%m%d")
|
56 |
+
path_in_repo = f"{SUBFOLDER}"
|
57 |
+
upload_folder(
|
58 |
+
folder_path=path,
|
59 |
+
path_in_repo=path_in_repo,
|
60 |
+
repo_id=REPO_ID,
|
61 |
+
repo_type="dataset"
|
62 |
+
)
|
63 |
+
return f"https://huggingface.co/datasets/{REPO_ID}/blob/main/{path_in_repo}"
|
64 |
+
# ------------------------------
|
65 |
# ------------------------------ ARGS ------------------------------
|
66 |
parser = argparse.ArgumentParser(description="Face Swapper (Multi-target, Male+Female Sources)")
|
67 |
parser.add_argument("--out_dir", default=os.getcwd())
|
|
|
181 |
output_path = temp_file.name
|
182 |
cv2.imwrite(output_path, out_frame) # Convert BGR to RGB before saving
|
183 |
output_files.append(output_path)
|
184 |
+
#upload_to_hf(output_path)
|
185 |
+
|
186 |
+
|
187 |
+
|
188 |
+
|
189 |
+
# Tạo thư mục tạm thời
|
190 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
191 |
+
print(f"Thư mục tạm thời được tạo: {temp_dir}")
|
192 |
+
|
193 |
+
# Lặp qua từng đường dẫn file trong danh sách
|
194 |
+
for source_file in output_files:
|
195 |
+
# Tạo đường dẫn đầy đủ cho file đích trong thư mục tạm
|
196 |
+
destination_file = os.path.join(temp_dir, os.path.basename(source_file))
|
197 |
+
|
198 |
+
# Sao chép file vào thư mục tạm
|
199 |
+
shutil.copy(source_file, destination_file)
|
200 |
+
print(f"Đã sao chép {source_file} vào {destination_file}")
|
201 |
+
|
202 |
+
# Tải lên thư mục tạm lên Hugging Face
|
203 |
+
upload_to_fd(temp_dir)
|
204 |
+
|
205 |
print(f"✔ Hoàn tất tất cả trong {time.time() - start_time:.2f}s")
|
206 |
return output_files
|
207 |
|