manavisrani07 commited on
Commit
506eed4
1 Parent(s): b695510

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from subprocess import call
3
 
 
4
  with gr.Blocks() as ui:
5
  with gr.Row():
6
  video = gr.File(label="Video or Image", info="Filepath of video/image that contains faces to use")
@@ -19,31 +20,35 @@ with gr.Blocks() as ui:
19
  with gr.Column():
20
  result = gr.Video()
21
 
22
- def generate(video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bottom, pad_left, pad_right):
23
- if video is None or audio is None or checkpoint is None:
24
- return
 
25
 
26
- smooth = "--nosmooth" if no_smooth else ""
27
 
28
-
29
- cmd = [
30
- "python",
31
- "inference.py",
32
- "--checkpoint_path", f"checkpoints/{checkpoint}.pth",
33
- "--segmentation_path", "checkpoints/face_segmentation.pth",
34
- "--enhance_face", "gfpgan",
35
- "--face", video.name,
36
- "--audio", audio.name,
37
- "--outfile", "results/output.mp4",
38
- ]
39
 
40
-
41
- call(cmd)
42
- return "results/output.mp4"
 
 
 
 
 
43
 
44
- generate_btn.click(
45
- generate,
46
- [video, audio, checkpoint, pad_top, pad_bottom, pad_left, pad_right, resize_factor],
47
- result)
48
 
49
- ui.queue().launch(share=True, debug=True, inline=False)
 
 
1
  import gradio as gr
2
  from subprocess import call
3
 
4
+ # UI Components Setup
5
  with gr.Blocks() as ui:
6
  with gr.Row():
7
  video = gr.File(label="Video or Image", info="Filepath of video/image that contains faces to use")
 
20
  with gr.Column():
21
  result = gr.Video()
22
 
23
+ # Define the generate function
24
+ def generate(video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bottom, pad_left, pad_right):
25
+ if video is None or audio is None or checkpoint is None:
26
+ return
27
 
28
+ smooth = "--nosmooth" if no_smooth else ""
29
 
30
+ cmd = [
31
+ "python",
32
+ "inference.py",
33
+ "--checkpoint_path", f"checkpoints/{checkpoint}.pth",
34
+ "--segmentation_path", "checkpoints/face_segmentation.pth",
35
+ "--enhance_face", "gfpgan",
36
+ "--face", video.name,
37
+ "--audio", audio.name,
38
+ "--outfile", "results/output.mp4",
39
+ ]
 
40
 
41
+ call(cmd)
42
+ return "results/output.mp4"
43
+
44
+ # Click event for the Generate button
45
+ generate_btn.click(
46
+ generate,
47
+ [video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bottom, pad_left, pad_right],
48
+ result)
49
 
50
+ # Create the interface
51
+ iface = gr.Interface(ui.queue(), "web", debug=True)
 
 
52
 
53
+ # Launch the interface
54
+ iface.launch()