-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradio_UI.py
65 lines (57 loc) Β· 3.28 KB
/
gradio_UI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# _*_ coding : utf-8 _*_
# @Time : 2023/11/7 21:42
# @Author : Black
# @File : gradio_UI
# @Project : face_fusion_damo
import gradio as gr
import os
from face_swap_utils import *
def face_swap(src_picture=None, src_video=None,
target_picture=os.path.join(os.path.dirname(__file__), 'example/Trump.jpg')):
save_dir = os.path.join(os.path.dirname(__file__), 'output')
# ζ£ζ₯ζ―ε¦εε¨δΈ΄ζΆζδ»Άε€ΉοΌε¦ζδΈεε¨εεε»Ί
if not os.path.exists(save_dir):
os.makedirs(save_dir)
if src_picture is not None:
print(src_picture)
result = replace_single_img(src_picture, target_picture, save_dir)
return result, None
elif src_video is not None:
print(src_video)
result = replace_video(src_video, target_picture)
return None, result
demo = gr.Interface(fn=face_swap,
inputs=[gr.Image(type='filepath'), gr.Video(), gr.Image(type='filepath')],
outputs=[gr.Image(type='filepath', label='swapped_image'),
gr.Video(label='swapped_video')],
title="π Painted Skin π",
description="# Face Swap Tool\n"
"Welcome to the π Painted Skin π! Get ready to have some fun with faces. π\n"
"## How it Works\n"
"This tool allows you to perform a face swap. Simply follow these steps:\n"
"1. **Upload Source:**\n"
" - Choose between `src_picture` and `src_video` for the face you want to swap.\n"
" - Note: You can only upload one source at a time, and the tool processes one task at a time.\n"
"2. **Upload Target:**\n"
" - Upload `target_picture`, and our model will swap the face onto the source image or video.\n"
"3. **Submit and Wait:**\n"
" - Click the submit button and patiently wait for the process to complete.\n"
" - Keep in mind that face swapping in videos might take some time, so be patient! π
\n"
"## Important Note\n"
"- Ensure that `target_picture` is uploaded for the face swap to work effectively.\n"
"Enjoy swapping faces and have a good laugh! π\n",
# css="body {background-color: red;}",
# article="Attention is all you need!",
examples=[[os.path.join(os.path.dirname(__file__), 'example/Trump.jpg'),
None,
os.path.join(os.path.dirname(__file__), 'example/Obama.jpg')],
[os.path.join(os.path.dirname(__file__), 'example/CXK.jpg'),
None,
os.path.join(os.path.dirname(__file__), 'example/James.jpg')]
],
# allow_flagging="never",
# cache_examples=True
)
if __name__ == "__main__":
# you can set share=False to disable the share button
demo.launch(share=True)