Spaces:
Running
Running
Update run.py
Browse files
run.py
CHANGED
|
@@ -6,33 +6,20 @@ from insightface.app import FaceAnalysis
|
|
| 6 |
import tempfile
|
| 7 |
from moviepy.editor import VideoFileClip
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
# Désactiver les warnings d'Albumentations (optionnel)
|
| 12 |
os.environ["NO_ALBUMENTATIONS_UPDATE"] = "1"
|
| 13 |
|
| 14 |
# Rediriger les chemins problématiques
|
| 15 |
os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib'
|
| 16 |
os.environ['FONTCONFIG_PATH'] = '/tmp/fontconfig'
|
| 17 |
-
os.environ['FONTCONFIG_FILE'] = '/tmp/fontconfig/fonts.conf'
|
| 18 |
-
|
| 19 |
-
# Créer les répertoires temporaires nécessaires
|
| 20 |
-
os.makedirs(os.environ['MPLCONFIGDIR'], exist_ok=True)
|
| 21 |
-
os.makedirs(os.environ['FONTCONFIG_PATH'], exist_ok=True)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
f.write('''<?xml version="1.0"?>
|
| 26 |
-
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
| 27 |
-
<fontconfig>
|
| 28 |
-
</fontconfig>''')
|
| 29 |
|
| 30 |
# Forcer InsightFace à utiliser un répertoire accessible
|
| 31 |
os.environ['INSIGHTFACE_ROOT'] = '/tmp/.insightface'
|
| 32 |
os.environ["ORT_DISABLE_CUDA"] = "1" # Désactiver CUDA si GPU indisponible
|
| 33 |
|
| 34 |
-
# ===== Fonction de swap de visage =====
|
| 35 |
-
|
| 36 |
def swap_face(source_face, target_face, frame):
|
| 37 |
src_emb = source_face.normed_embedding
|
| 38 |
tgt_bbox = target_face.bbox.astype(int)
|
|
@@ -48,7 +35,6 @@ def swap_face(source_face, target_face, frame):
|
|
| 48 |
result = cv2.seamlessClone(resized_face, frame, mask, center, cv2.NORMAL_CLONE)
|
| 49 |
return result
|
| 50 |
|
| 51 |
-
|
| 52 |
def process_video(source_img, target_video):
|
| 53 |
try:
|
| 54 |
face_app = FaceAnalysis(name="buffalo_l", root="/tmp/.insightface")
|
|
@@ -96,9 +82,7 @@ def process_video(source_img, target_video):
|
|
| 96 |
print(f"Erreur lors du traitement : {str(e)}")
|
| 97 |
return None
|
| 98 |
|
| 99 |
-
|
| 100 |
-
# ===== Interface Gradio =====
|
| 101 |
-
|
| 102 |
demo = gr.Interface(
|
| 103 |
fn=process_video,
|
| 104 |
inputs=[
|
|
@@ -111,6 +95,5 @@ demo = gr.Interface(
|
|
| 111 |
allow_flagging="never"
|
| 112 |
)
|
| 113 |
|
| 114 |
-
|
| 115 |
if __name__ == "__main__":
|
| 116 |
demo.launch(share=True)
|
|
|
|
| 6 |
import tempfile
|
| 7 |
from moviepy.editor import VideoFileClip
|
| 8 |
|
| 9 |
+
# Désactiver les avertissements d'Albumentations
|
|
|
|
|
|
|
| 10 |
os.environ["NO_ALBUMENTATIONS_UPDATE"] = "1"
|
| 11 |
|
| 12 |
# Rediriger les chemins problématiques
|
| 13 |
os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib'
|
| 14 |
os.environ['FONTCONFIG_PATH'] = '/tmp/fontconfig'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
os.makedirs('/tmp/matplotlib', exist_ok=True)
|
| 17 |
+
os.makedirs('/tmp/fontconfig', exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Forcer InsightFace à utiliser un répertoire accessible
|
| 20 |
os.environ['INSIGHTFACE_ROOT'] = '/tmp/.insightface'
|
| 21 |
os.environ["ORT_DISABLE_CUDA"] = "1" # Désactiver CUDA si GPU indisponible
|
| 22 |
|
|
|
|
|
|
|
| 23 |
def swap_face(source_face, target_face, frame):
|
| 24 |
src_emb = source_face.normed_embedding
|
| 25 |
tgt_bbox = target_face.bbox.astype(int)
|
|
|
|
| 35 |
result = cv2.seamlessClone(resized_face, frame, mask, center, cv2.NORMAL_CLONE)
|
| 36 |
return result
|
| 37 |
|
|
|
|
| 38 |
def process_video(source_img, target_video):
|
| 39 |
try:
|
| 40 |
face_app = FaceAnalysis(name="buffalo_l", root="/tmp/.insightface")
|
|
|
|
| 82 |
print(f"Erreur lors du traitement : {str(e)}")
|
| 83 |
return None
|
| 84 |
|
| 85 |
+
# Interface Gradio
|
|
|
|
|
|
|
| 86 |
demo = gr.Interface(
|
| 87 |
fn=process_video,
|
| 88 |
inputs=[
|
|
|
|
| 95 |
allow_flagging="never"
|
| 96 |
)
|
| 97 |
|
|
|
|
| 98 |
if __name__ == "__main__":
|
| 99 |
demo.launch(share=True)
|