File size: 1,072 Bytes
5664dc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#! /usr/bin/env python
import os
import cv2
import argparse
import streamlit as st
from face_detection import select_face, select_all_faces
from face_swap import face_swap
import gradio as gr
from PIL import Image

def swap():

    src_img = st.file_uploader("Source Image", type=["jpg", "png", "jpeg"])
    dst_img = st.file_uploader("Destination Image", type=["jpg", "png", "jpeg"])


    src_img = cv2.imread(src_img.name)
    dst_img = cv2.imread(Image.open(dst_img))

    src_points, src_shape, src_face = select_face(src_img)

    dst_faceBoxes = select_all_faces(dst_img)

    if dst_faceBoxes is None:
        print('Detect 0 Face !!')
        exit(-1)

    output = dst_img
    for k, dst_face in dst_faceBoxes.items():
        output = face_swap(src_face, dst_face["face"], src_points,
                            dst_face["points"], dst_face["shape"],
                            output, "correct color")

    return output
if __name__ == '__main__':
    swap()
    # demo = gr.Interface(fn=main, inputs=["image", "image"], outputs="image")
    # demo.launch()