sandhyasinha655 commited on
Commit
79396cb
·
verified ·
1 Parent(s): 5675cb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -18
app.py CHANGED
@@ -1,29 +1,50 @@
1
-
2
  import gradio as gr
3
  import os
4
  from run import run_faceswap
5
 
6
- def process_face_swap(source_image, target_media):
7
  source_path = "face.png"
8
  target_path = "target"
9
 
 
10
  source_image.save(source_path)
11
- ext = os.path.splitext(target_media.name)[-1]
12
- target_path += ext
13
- target_media.save(target_path)
14
 
15
- output_path = run_faceswap(source_path, target_path)
 
 
 
 
 
 
 
 
 
 
 
 
16
  return output_path
17
 
18
- iface = gr.Interface(
19
- fn=process_face_swap,
20
- inputs=[
21
- gr.Image(label="Source Face (face.png)"),
22
- gr.File(label="Target Image or Video (.jpg/.mp4)")
23
- ],
24
- outputs=gr.File(label="Swapped Output"),
25
- title="Lightweight Roop Face Swap",
26
- description="Upload face.png and target image/video. Output will be result.jpg or result.mp4"
27
- )
28
-
29
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import os
3
  from run import run_faceswap
4
 
5
+ def process_face_swap(source_image, target_image, target_video):
6
  source_path = "face.png"
7
  target_path = "target"
8
 
9
+ # Save source image
10
  source_image.save(source_path)
 
 
 
11
 
12
+ # Use whichever is provided (image or video)
13
+ if target_image is not None:
14
+ ext = ".jpg"
15
+ target_image.save(target_path + ext)
16
+ used_path = target_path + ext
17
+ elif target_video is not None:
18
+ ext = ".mp4"
19
+ target_video.save(target_path + ext)
20
+ used_path = target_path + ext
21
+ else:
22
+ raise ValueError("Please upload either an image or a video.")
23
+
24
+ output_path = run_faceswap(source_path, used_path)
25
  return output_path
26
 
27
+ with gr.Blocks() as demo:
28
+ gr.Markdown("## Lightweight Roop Face Swap")
29
+ gr.Markdown("Upload face.png and target image or video. Output will be result.jpg or result.mp4")
30
+
31
+ with gr.Row():
32
+ source_image = gr.Image(label="Source Face (face.png)", type="pil")
33
+
34
+ with gr.Row():
35
+ with gr.Tab("Target Image"):
36
+ target_image = gr.Image(label="Upload Target Image (.jpg)", type="pil")
37
+ with gr.Tab("Target Video"):
38
+ target_video = gr.Video(label="Upload Target Video (.mp4)")
39
+
40
+ output_file = gr.File(label="Swapped Output")
41
+
42
+ submit_btn = gr.Button("Submit")
43
+
44
+ submit_btn.click(
45
+ fn=process_face_swap,
46
+ inputs=[source_image, target_image, target_video],
47
+ outputs=output_file
48
+ )
49
+
50
+ demo.launch()