manavisrani07 commited on
Commit
b24dca3
1 Parent(s): ec0fc56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from subprocess import call
3
 
4
- # UI Components Setup with the generate function
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")
@@ -19,30 +18,31 @@ with gr.Blocks() as ui:
19
  generate_btn = gr.Button("Generate")
20
  with gr.Column():
21
  result = gr.Video()
 
 
 
 
22
 
23
- # Define the generate function
24
- def generate():
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
- "python3.8", # Use Python 3.8
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
- result.value = "results/output.mp4"
43
 
44
- # Create the interface
45
- iface = gr.Interface(ui.queue(), generate_btn)
 
46
 
47
- # Launch the interface
48
- iface.launch(share=True)
 
 
 
 
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")
 
18
  generate_btn = gr.Button("Generate")
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
+ ui.queue().launch()