Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
from refacer import Refacer
|
3 |
-
import argparse
|
4 |
import ngrok
|
5 |
import time
|
6 |
-
|
7 |
-
# Argument parser
|
8 |
-
parser = argparse.ArgumentParser(description='Refacer')
|
9 |
-
parser.add_argument("--max_num_faces", type=int, help="Max number of faces on UI", default=5)
|
10 |
-
parser.add_argument("--force_cpu", help="Force CPU mode", default=False, action="store_true")
|
11 |
-
parser.add_argument("--share_gradio", help="Share Gradio", default=False, action="store_true")
|
12 |
-
parser.add_argument("--server_name", type=str, help="Server IP address", default="127.0.0.1")
|
13 |
-
parser.add_argument("--server_port", type=int, help="Server port", default=7860)
|
14 |
-
parser.add_argument("--colab_performance", help="Use in colab for better performance", default=False, action="store_true")
|
15 |
-
parser.add_argument("--ngrok", type=str, help="Use ngrok", default=None)
|
16 |
-
parser.add_argument("--ngrok_region", type=str, help="ngrok region", default="us")
|
17 |
-
args = parser.parse_args()
|
18 |
|
19 |
# Initialize Refacer
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
|
26 |
# Ngrok connection
|
27 |
def connect(token, port, options):
|
@@ -65,6 +54,7 @@ def run(*vars):
|
|
65 |
origin = []
|
66 |
destination = []
|
67 |
thresholds = []
|
|
|
68 |
|
69 |
with gr.Blocks() as demo:
|
70 |
with gr.Row():
|
@@ -86,8 +76,9 @@ with gr.Blocks() as demo:
|
|
86 |
|
87 |
button.click(fn=run, inputs=[video] + origin + destination + thresholds, outputs=[video2])
|
88 |
|
89 |
-
|
90 |
-
|
|
|
91 |
|
92 |
# Launch demo
|
93 |
-
demo.queue().launch(show_error=True, share=
|
|
|
1 |
import gradio as gr
|
2 |
from refacer import Refacer
|
|
|
3 |
import ngrok
|
4 |
import time
|
5 |
+
import threading
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Initialize Refacer
|
8 |
+
def initialize_refacer():
|
9 |
+
global refacer
|
10 |
+
print("Initializing Refacer...")
|
11 |
+
start_time = time.time()
|
12 |
+
refacer = Refacer(force_cpu=False, colab_performance=False)
|
13 |
+
print(f"Refacer initialized in {time.time() - start_time:.2f} seconds")
|
14 |
|
15 |
# Ngrok connection
|
16 |
def connect(token, port, options):
|
|
|
54 |
origin = []
|
55 |
destination = []
|
56 |
thresholds = []
|
57 |
+
num_faces = 5
|
58 |
|
59 |
with gr.Blocks() as demo:
|
60 |
with gr.Row():
|
|
|
76 |
|
77 |
button.click(fn=run, inputs=[video] + origin + destination + thresholds, outputs=[video2])
|
78 |
|
79 |
+
# Start initialization in a separate thread to prevent blocking
|
80 |
+
init_thread = threading.Thread(target=initialize_refacer)
|
81 |
+
init_thread.start()
|
82 |
|
83 |
# Launch demo
|
84 |
+
demo.queue().launch(show_error=True, share=True, server_name="0.0.0.0", server_port=7860)
|