Added command line arguments for --share_gradio #7. Implemented multithreaded parallel processing and CoreML optimization, still pending CUDA optimization #5.
This commit is contained in:
23
app.py
23
app.py
@@ -1,20 +1,25 @@
|
||||
import gradio as gr
|
||||
from refacer import Refacer
|
||||
import argparse
|
||||
|
||||
MAX_NUM_OF_FACES=8
|
||||
parser = argparse.ArgumentParser(description='Refacer')
|
||||
parser.add_argument("--max_num_faces", help="Max number of faces on UI", default=5)
|
||||
parser.add_argument("--force_cpu", help="Force CPU mode", default=False,action="store_true")
|
||||
parser.add_argument("--share_gradio", help="Share Gradio", default=False,action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
refacer = Refacer()
|
||||
refacer = Refacer(force_cpu=args.force_cpu)
|
||||
|
||||
n=MAX_NUM_OF_FACES
|
||||
num_faces=args.max_num_faces
|
||||
|
||||
def run(*vars):
|
||||
video_path=vars[0]
|
||||
origins=vars[1:(n+1)]
|
||||
destinations=vars[(n+1):(n*2)+1]
|
||||
thresholds=vars[(n*2)+1:]
|
||||
origins=vars[1:(num_faces+1)]
|
||||
destinations=vars[(num_faces+1):(num_faces*2)+1]
|
||||
thresholds=vars[(num_faces*2)+1:]
|
||||
|
||||
faces = []
|
||||
for k in range(0,n):
|
||||
for k in range(0,num_faces):
|
||||
if origins[k] is not None and destinations[k] is not None:
|
||||
faces.append({
|
||||
'origin':origins[k],
|
||||
@@ -35,7 +40,7 @@ with gr.Blocks() as demo:
|
||||
video=gr.Video(label="Original video")
|
||||
video2=gr.Video(label="Refaced video",interactive=False)
|
||||
|
||||
for i in range(0,MAX_NUM_OF_FACES):
|
||||
for i in range(0,num_faces):
|
||||
with gr.Tab(f"Face #{i+1}"):
|
||||
with gr.Row():
|
||||
origin.append(gr.Image(label="Face to replace"))
|
||||
@@ -48,4 +53,4 @@ with gr.Blocks() as demo:
|
||||
button.click(fn=run,inputs=[video]+origin+destination+thresholds,outputs=[video2])
|
||||
|
||||
#demo.launch(share=True,server_name="0.0.0.0", show_error=True)
|
||||
demo.queue().launch(show_error=True,share=True)
|
||||
demo.queue().launch(show_error=True,share=args.share_gradio)
|
||||
Reference in New Issue
Block a user