File size: 1,337 Bytes
800135a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from prodiapy import Prodia
from PIL import Image
from io import BytesIO
import requests
import base64

client = Prodia()


def run_face_swap(source_image, target_image):
    if source_image is None or target_image is None:
        return

    print(source_image, target_image)

    return "https://images.prodia.xyz/acfe8b01-b706-46d9-8c2d-287466337609.png"


def image_to_base64(image: Image):
    # Convert the image to bytes
    buffered = BytesIO()
    image.save(buffered, format="PNG")  # You can change format to PNG if needed

    # Encode the bytes to base64
    img_str = base64.b64encode(buffered.getvalue())

    return img_str.decode('utf-8')  # Convert bytes to string


with gr.Blocks() as demo:
    with gr.Column():
        gr.HTML("<h1><center>Face Swap</center></h1>")
        gr.DuplicateButton(size="lg")

    with gr.Row():
        with gr.Column():
            source_image = gr.Image(type="filepath", label="Source Image")
            target_image = gr.Image(type="filepath", label="Target Image")
        with gr.Column():
            run_button = gr.Button("Swap Faces", variant="primary")
            result = gr.Image()

    run_button.click(fn=run_face_swap, inputs=[source_image, target_image], outputs=result)

demo.launch(show_api=False)