File size: 1,030 Bytes
3266b60
fa3cda5
2520dea
 
fa3cda5
2520dea
 
 
 
fa3cda5
 
 
2520dea
 
570f004
2520dea
fa3cda5
 
 
 
570f004
 
fa3cda5
 
 
 
2520dea
fa3cda5
 
 
 
 
 
 
 
 
 
3266b60
 
fa3cda5
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
import gradio as gr
from gradio_client import Client, handle_file
import os
import random

KEYS = os.getenv("KEYS").split(",")

def get_random_api_key():
    return random.choice(KEYS)

def swap_face_api(source_img, target_img, doFaceEnhancer):
    try:
        api_key = get_random_api_key()

        client = Client("tuan2308/face-swap")

        result = client.predict(
            source_file=handle_file(source_img),
            target_file=handle_file(target_img),
            doFaceEnhancer=doFaceEnhancer,
            api_name="/predict",
            api_key=api_key
        )
        return result
    except Exception as e:
        print(f"Ошибка при вызове API: {e}")
        return None

iface = gr.Interface(
    fn=swap_face_api,
    inputs=[
        gr.Image(type="filepath", label="Source Image"),
        gr.Image(type="filepath", label="Target Image"),
        gr.Checkbox(label="Face Enhancer?")
    ],
    outputs=gr.Image(label="Output Image"),
    title="Face Swap via API"
)

iface.launch()