File size: 1,628 Bytes
73a0ac5
008f98b
73a0ac5
 
 
517cbd1
73a0ac5
 
 
 
517cbd1
73a0ac5
 
 
 
 
 
 
517cbd1
73a0ac5
 
 
517cbd1
73a0ac5
008f98b
 
73a0ac5
 
 
 
517cbd1
73a0ac5
 
 
517cbd1
065663b
73a0ac5
 
 
 
 
 
 
 
 
 
 
 
065663b
e4f5d03
008f98b
73a0ac5
 
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
import gradio as gr
from gradio_client import Client, file
import os
import shutil


client_gen_image = Client("AP123/SDXL-Lightning")
client_face_swap = Client("craftgamesnetwork/face-swap")

def generate_and_swap(text_input, source_image_path):
    
    gen_result = client_gen_image.predict(
        text_input,  # Text input
        "4-Step",    # Inference steps
        api_name="/generate_image"
    )
    print("Image generated successfully.")

    
    generated_image_path = "generated_image.png"
    shutil.move(gen_result, generated_image_path)

    
    swap_result_path = client_face_swap.predict(
        file(generated_image_path),
        file(source_image_path),
        api_name="/predict"
    )
    print("Faces swapped successfully.")

    
    with open(swap_result_path, "rb") as f:
        swap_result_content = f.read()

    
    swapped_image_path = "final_image.png"
    with open(swapped_image_path, "wb") as f:
        f.write(swap_result_content)

    print("Swapped image saved as:", swapped_image_path)
    return swapped_image_path

iface = gr.Interface(
    generate_and_swap,
    [
        gr.Textbox(label="Enter your prompt (English):"),
        gr.Image(type="filepath", label="Upload your source image:")
    ],
    "image",
    description="Generate free AI image with your or any face. Support me in making better AI codes as I am a solo developer [Click here to Donate](https://nowpayments.io/donation/aheed) Contact me for bulk processing and better AI software +92-332-4399819 Please do not duplicate this space without permission",
    title="AI Image with Any Face"
)
iface.launch()