Spaces:
Runtime error
Runtime error
aheedsajid
commited on
Commit
•
73a0ac5
1
Parent(s):
9636059
Upload 2 files
Browse files- app.py +52 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
import os
|
4 |
+
import shutil
|
5 |
+
|
6 |
+
# Load the APIs at the beginning
|
7 |
+
client_gen_image = Client("AP123/SDXL-Lightning")
|
8 |
+
client_face_swap = Client("craftgamesnetwork/face-swap")
|
9 |
+
|
10 |
+
def generate_and_swap(text_input, source_image_path):
|
11 |
+
# First API: Generate image from text input
|
12 |
+
gen_result = client_gen_image.predict(
|
13 |
+
text_input, # Text input
|
14 |
+
"4-Step", # Inference steps
|
15 |
+
api_name="/generate_image"
|
16 |
+
)
|
17 |
+
print("Image generated successfully.")
|
18 |
+
|
19 |
+
# Move the generated image to a known location
|
20 |
+
generated_image_path = "generated_image.png"
|
21 |
+
shutil.move(gen_result, generated_image_path)
|
22 |
+
|
23 |
+
# Second API: Face swap
|
24 |
+
swap_result_path = client_face_swap.predict(
|
25 |
+
generated_image_path, # Provide generated image path directly
|
26 |
+
source_image_path, # Provide source image path directly
|
27 |
+
api_name="/predict"
|
28 |
+
)
|
29 |
+
print("Faces swapped successfully.")
|
30 |
+
|
31 |
+
# Read the swapped image file
|
32 |
+
with open(swap_result_path, "rb") as f:
|
33 |
+
swap_result_content = f.read()
|
34 |
+
|
35 |
+
# Save swapped image to a file
|
36 |
+
swapped_image_path = "swapped_image.png"
|
37 |
+
with open(swapped_image_path, "wb") as f:
|
38 |
+
f.write(swap_result_content)
|
39 |
+
|
40 |
+
print("Swapped image saved as:", swapped_image_path)
|
41 |
+
return swapped_image_path
|
42 |
+
|
43 |
+
iface = gr.Interface(
|
44 |
+
generate_and_swap,
|
45 |
+
[
|
46 |
+
gr.Textbox(label="Enter your prompt (English):"),
|
47 |
+
gr.Image(type="filepath", label="Upload your source image:")
|
48 |
+
],
|
49 |
+
"image", # Output type is directly specified as "image"
|
50 |
+
title="Face Swap"
|
51 |
+
)
|
52 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio==2.3.0
|
2 |
+
gradio-client==2.0.0
|