Ii commited on
Commit
7b9a1df
·
verified ·
1 Parent(s): 3179518

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -3,6 +3,7 @@ from refacer import Refacer
3
  import argparse
4
  import os
5
  import requests
 
6
 
7
  # Hugging Face URL to download the model
8
  model_url = "https://huggingface.co/ofter/4x-UltraSharp/resolve/main/inswapper_128.onnx"
@@ -55,11 +56,16 @@ def run(video_path, *vars):
55
  'threshold': thresholds[k]
56
  })
57
 
58
- # Call refacer to process video and get file path
59
- refaced_video_path = refacer.reface(video_path, faces) # refaced video path
60
- print(f"Refaced video can be found at {refaced_video_path}")
61
-
62
- return refaced_video_path # Directly return the refaced video path
 
 
 
 
 
63
 
64
  # Prepare Gradio components
65
  origin = []
 
3
  import argparse
4
  import os
5
  import requests
6
+ import tempfile
7
 
8
  # Hugging Face URL to download the model
9
  model_url = "https://huggingface.co/ofter/4x-UltraSharp/resolve/main/inswapper_128.onnx"
 
56
  'threshold': thresholds[k]
57
  })
58
 
59
+ # Call refacer to process video, output saved temporarily
60
+ with tempfile.NamedTemporaryFile(suffix=".mp4", delete=True) as temp_file:
61
+ temp_video_path = temp_file.name
62
+ refaced_video_path = refacer.reface(video_path, faces, output_path=temp_video_path)
63
+ print(f"Processing completed. Video available temporarily.")
64
+
65
+ # Load video content as bytes and return to Gradio
66
+ with open(refaced_video_path, "rb") as video_file:
67
+ video_data = video_file.read()
68
+ return video_data
69
 
70
  # Prepare Gradio components
71
  origin = []