adfly450 commited on
Commit
2e1cd25
·
verified ·
1 Parent(s): 1033d03

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -89
app.py DELETED
@@ -1,89 +0,0 @@
1
- import gradio as gr
2
- from refacer import Refacer
3
- import argparse
4
- import ngrok
5
-
6
- parser = argparse.ArgumentParser(description='Refacer')
7
- parser.add_argument("--max_num_faces", type=int, help="Max number of faces on UI", default=5)
8
- parser.add_argument("--force_cpu", help="Force CPU mode", default=False, action="store_true")
9
- parser.add_argument("--share_gradio", help="Share Gradio", default=False, action="store_true")
10
- parser.add_argument("--server_name", type=str, help="Server IP address", default="127.0.0.1")
11
- parser.add_argument("--server_port", type=int, help="Server port", default=7860)
12
- parser.add_argument("--colab_performance", help="Use in colab for better performance", default=False,action="store_true")
13
- parser.add_argument("--ngrok", type=str, help="Use ngrok", default=None)
14
- parser.add_argument("--ngrok_region", type=str, help="ngrok region", default="us")
15
- args = parser.parse_args()
16
-
17
- refacer = Refacer(force_cpu=args.force_cpu,colab_performance=args.colab_performance)
18
-
19
- num_faces=args.max_num_faces
20
-
21
- # Connect to ngrok for ingress
22
- def connect(token, port, options):
23
- account = None
24
- if token is None:
25
- token = 'None'
26
- else:
27
- if ':' in token:
28
- token, username, password = token.split(':', 2)
29
- account = f"{username}:{password}"
30
-
31
- if not options.get('authtoken_from_env'):
32
- options['authtoken'] = token
33
- if account:
34
- options['basic_auth'] = account
35
-
36
- try:
37
- public_url = ngrok.connect(f"127.0.0.1:{port}", **options).url()
38
- except Exception as e:
39
- print(f'Invalid ngrok authtoken? ngrok connection aborted due to: {e}\n'
40
- f'Your token: {token}, get the right one on https://dashboard.ngrok.com/get-started/your-authtoken')
41
- else:
42
- print(f'ngrok connected to localhost:{port}! URL: {public_url}\n'
43
- 'You can use this link after the launch is complete.')
44
-
45
- def run(*vars):
46
- video_path=vars[0]
47
- origins=vars[1:(num_faces+1)]
48
- destinations=vars[(num_faces+1):(num_faces*2)+1]
49
- thresholds=vars[(num_faces*2)+1:]
50
-
51
- faces = []
52
- for k in range(0,num_faces):
53
- if origins[k] is not None and destinations[k] is not None:
54
- faces.append({
55
- 'origin':origins[k],
56
- 'destination':destinations[k],
57
- 'threshold':thresholds[k]
58
- })
59
-
60
- return refacer.reface(video_path,faces)
61
-
62
- origin = []
63
- destination = []
64
- thresholds = []
65
-
66
- with gr.Blocks() as demo:
67
- with gr.Row():
68
- gr.Markdown("# Refacer")
69
- with gr.Row():
70
- video=gr.Video(label="Original video",format="mp4")
71
- video2=gr.Video(label="Refaced video",interactive=False,format="mp4")
72
-
73
- for i in range(0,num_faces):
74
- with gr.Tab(f"Face #{i+1}"):
75
- with gr.Row():
76
- origin.append(gr.Image(label="Face to replace"))
77
- destination.append(gr.Image(label="Destination face"))
78
- with gr.Row():
79
- thresholds.append(gr.Slider(label="Threshold",minimum=0.0,maximum=1.0,value=0.2))
80
- with gr.Row():
81
- button=gr.Button("Reface", variant="primary")
82
-
83
- button.click(fn=run,inputs=[video]+origin+destination+thresholds,outputs=[video2])
84
-
85
- if args.ngrok is not None:
86
- connect(args.ngrok, args.server_port, {'region': args.ngrok_region, 'authtoken_from_env': False})
87
-
88
- # demo.launch(share=True, server_name="0.0.0.0", show_error=True)
89
- demo.queue().launch(show_error=True, share=args.share_gradio, server_name=args.server_name, server_port=args.server_port)