Ii
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,30 @@ import gradio as gr
|
|
2 |
from refacer import Refacer
|
3 |
import argparse
|
4 |
import os
|
|
|
|
|
|
|
5 |
|
6 |
-
# Hugging Face
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Argument parser
|
10 |
parser = argparse.ArgumentParser(description='Refacer')
|
@@ -21,7 +42,7 @@ refacer = Refacer(force_cpu=args.force_cpu, colab_performance=args.colab_perform
|
|
21 |
|
22 |
num_faces = args.max_num_faces
|
23 |
|
24 |
-
# Run function for refacing video
|
25 |
def run(*vars):
|
26 |
video_path = vars[0]
|
27 |
origins = vars[1:(num_faces+1)]
|
@@ -37,11 +58,11 @@ def run(*vars):
|
|
37 |
'threshold': thresholds[k]
|
38 |
})
|
39 |
|
40 |
-
# Call refacer to process video
|
41 |
-
refaced_video_path = refacer.reface(video_path, faces) # refaced video path
|
42 |
print(f"Refaced video can be found at {refaced_video_path}")
|
43 |
|
44 |
-
#
|
45 |
return refaced_video_path # Gradio will handle the video display
|
46 |
|
47 |
# Prepare Gradio components
|
|
|
2 |
from refacer import Refacer
|
3 |
import argparse
|
4 |
import os
|
5 |
+
import requests
|
6 |
+
import tempfile
|
7 |
+
import shutil
|
8 |
|
9 |
+
# Hugging Face URL to download the model
|
10 |
+
model_url = "https://huggingface.co/ofter/4x-UltraSharp/resolve/main/inswapper_128.onnx"
|
11 |
+
model_path = "/home/user/app/inswapper_128.onnx" # absolute path for the model in your environment
|
12 |
+
|
13 |
+
# Function to download the model if not exists
|
14 |
+
def download_model():
|
15 |
+
if not os.path.exists(model_path):
|
16 |
+
print("Downloading the inswapper_128.onnx model...")
|
17 |
+
response = requests.get(model_url)
|
18 |
+
if response.status_code == 200:
|
19 |
+
with open(model_path, 'wb') as f:
|
20 |
+
f.write(response.content)
|
21 |
+
print("Model downloaded successfully!")
|
22 |
+
else:
|
23 |
+
print(f"Error: Model download failed. Status code: {response.status_code}")
|
24 |
+
else:
|
25 |
+
print("Model already exists.")
|
26 |
+
|
27 |
+
# Download the model when the script runs
|
28 |
+
download_model()
|
29 |
|
30 |
# Argument parser
|
31 |
parser = argparse.ArgumentParser(description='Refacer')
|
|
|
42 |
|
43 |
num_faces = args.max_num_faces
|
44 |
|
45 |
+
# Run function for refacing video
|
46 |
def run(*vars):
|
47 |
video_path = vars[0]
|
48 |
origins = vars[1:(num_faces+1)]
|
|
|
58 |
'threshold': thresholds[k]
|
59 |
})
|
60 |
|
61 |
+
# Call refacer to process video and get refaced video path
|
62 |
+
refaced_video_path = refacer.reface(video_path, faces) # Get refaced video path
|
63 |
print(f"Refaced video can be found at {refaced_video_path}")
|
64 |
|
65 |
+
# Directly return the path to the Gradio UI without using ffmpeg or temp files
|
66 |
return refaced_video_path # Gradio will handle the video display
|
67 |
|
68 |
# Prepare Gradio components
|