assile commited on
Commit
0a4e356
·
verified ·
1 Parent(s): 495a7a7

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +6 -7
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 avec des permissions
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 pour éviter les problèmes de chargement
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
- # Réencodage pour compatibilité Gradio/HF
76
- clip = VideoFileClip(temp_output.name)
77
- final_path = temp_output.name.replace(".mp4", "_final.mp4")
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