Spaces:
Running
Running
Update run.py
Browse files
run.py
CHANGED
|
@@ -3,10 +3,10 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
from insightface.app import FaceAnalysis
|
| 5 |
import tempfile
|
| 6 |
-
from moviepy.editor import VideoFileClip
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
-
# Forcer InsightFace à utiliser un répertoire
|
| 10 |
os.environ['INSIGHTFACE_ROOT'] = '/tmp/.insightface'
|
| 11 |
|
| 12 |
def swap_face(source_face, target_face, frame):
|
|
@@ -35,7 +35,7 @@ def swap_face(source_face, target_face, frame):
|
|
| 35 |
|
| 36 |
def process_video(source_img, target_video):
|
| 37 |
try:
|
| 38 |
-
# Initialiser le modèle INSIDE la fonction
|
| 39 |
face_app = FaceAnalysis(name="buffalo_l", root="/tmp/.insightface")
|
| 40 |
face_app.prepare(ctx_id=0, det_size=(640, 640))
|
| 41 |
|
|
@@ -72,10 +72,9 @@ def process_video(source_img, target_video):
|
|
| 72 |
cap.release()
|
| 73 |
out.release()
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
clip.write_videofile(final_path, codec="libx264", audio_codec="aac")
|
| 79 |
|
| 80 |
return final_path
|
| 81 |
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from insightface.app import FaceAnalysis
|
| 5 |
import tempfile
|
|
|
|
| 6 |
import os
|
| 7 |
+
import shutil
|
| 8 |
|
| 9 |
+
# Forcer InsightFace à utiliser un répertoire accessible
|
| 10 |
os.environ['INSIGHTFACE_ROOT'] = '/tmp/.insightface'
|
| 11 |
|
| 12 |
def swap_face(source_face, target_face, frame):
|
|
|
|
| 35 |
|
| 36 |
def process_video(source_img, target_video):
|
| 37 |
try:
|
| 38 |
+
# Initialiser le modèle INSIDE la fonction
|
| 39 |
face_app = FaceAnalysis(name="buffalo_l", root="/tmp/.insightface")
|
| 40 |
face_app.prepare(ctx_id=0, det_size=(640, 640))
|
| 41 |
|
|
|
|
| 72 |
cap.release()
|
| 73 |
out.release()
|
| 74 |
|
| 75 |
+
# Copier vers un nouveau fichier stable
|
| 76 |
+
final_path = tempfile.mktemp(suffix=".mp4")
|
| 77 |
+
shutil.copy(temp_output.name, final_path)
|
|
|
|
| 78 |
|
| 79 |
return final_path
|
| 80 |
|