Spaces:
Running
Running
Update run.py
Browse files
run.py
CHANGED
|
@@ -6,19 +6,19 @@ from insightface.app import FaceAnalysis
|
|
| 6 |
import tempfile
|
| 7 |
from moviepy.editor import VideoFileClip
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
os.environ["NO_ALBUMENTATIONS_UPDATE"] = "1"
|
|
|
|
|
|
|
| 12 |
os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib'
|
| 13 |
os.environ['FONTCONFIG_PATH'] = '/tmp/fontconfig'
|
| 14 |
|
| 15 |
os.makedirs('/tmp/matplotlib', exist_ok=True)
|
| 16 |
os.makedirs('/tmp/fontconfig', exist_ok=True)
|
| 17 |
|
|
|
|
| 18 |
os.environ['INSIGHTFACE_ROOT'] = '/tmp/.insightface'
|
| 19 |
-
os.environ["ORT_DISABLE_CUDA"] = "1"
|
| 20 |
-
|
| 21 |
-
# ===== Fonction de swap =====
|
| 22 |
|
| 23 |
def swap_face(source_face, target_face, frame):
|
| 24 |
src_emb = source_face.normed_embedding
|
|
@@ -78,19 +78,18 @@ def process_video(source_img, target_video):
|
|
| 78 |
return final_path
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
-
print(f"Erreur : {str(e)}")
|
| 82 |
return None
|
| 83 |
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
demo = gr.Interface(
|
| 88 |
fn=process_video,
|
| 89 |
inputs=[
|
| 90 |
-
gr.Image(label="Visage Source", type="numpy"),
|
| 91 |
-
gr.Video(label="Vidéo Cible"),
|
| 92 |
],
|
| 93 |
-
outputs=gr.Video(label="Vidéo Résultat"),
|
| 94 |
title="🎬 FaceSwap Pro",
|
| 95 |
description="Échangez des visages dans une vidéo.",
|
| 96 |
allow_flagging="never"
|
|
|
|
| 6 |
import tempfile
|
| 7 |
from moviepy.editor import VideoFileClip
|
| 8 |
|
| 9 |
+
# Désactiver les warnings 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
|
|
|
|
| 78 |
return final_path
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
+
print(f"Erreur lors du traitement : {str(e)}")
|
| 82 |
return None
|
| 83 |
|
| 84 |
|
| 85 |
+
# Interface Gradio
|
|
|
|
| 86 |
demo = gr.Interface(
|
| 87 |
fn=process_video,
|
| 88 |
inputs=[
|
| 89 |
+
gr.Image(label="Visage Source", type="numpy"),
|
| 90 |
+
gr.Video(label="Vidéo Cible"),
|
| 91 |
],
|
| 92 |
+
outputs=gr.Video(label="Vidéo Résultat"),
|
| 93 |
title="🎬 FaceSwap Pro",
|
| 94 |
description="Échangez des visages dans une vidéo.",
|
| 95 |
allow_flagging="never"
|