File size: 1,461 Bytes
34caf6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from gradio_client import Client

sdxl_client = Client("https://fffiloni-sdxl-dpo.hf.space/--replicas/8llck/")
faceswap_client = Client("https://tonyassi-face-swap.hf.space/")

def infer(portrait_in, prompt_in):
    # Generate Image from SDXL
    gr.Info("Generating SDXL image first ...")
    sdxl_result = sdxl_client.predict(
        prompt_in,
        api_name="/infer"
    )

    # Face Swap
    gr.Info("Face swap your face on result ...")
    faceswap_result = faceswap_client.predict(
    	portrait_in,
        sdxl_result,
        api_name="/predict"
    )

    return faceswap_result

css = """
#col-container{
    margin: 0 auto;
    max-width: 840px;
}
"""
with gr.Blocks(css=css) as demo:
    with gr.Column(elem_id="col-container"):
        gr.HTML("""
        <h2 style="text-align: center;">Portrait Maker</h2>
        """)
        with gr.Row():
            with gr.Column():
                portrait_in = gr.Image(label="Your face portrait", type="filepath")
                prompt_in = gr.Textbox(label="Prompt to desired portrait using your own face")
                submit_btn = gr.Button("Submit")
            with gr.Column():
                result = gr.Image(label="Result")

        submit_btn.click(
            fn = infer, 
            inputs = [
                portrait_in,
                prompt_in
            ],
            outputs = [
                result
            ]  
        )

demo.queue().launch()