Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +46 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from prodiapy import Prodia
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
import requests
|
| 6 |
+
import base64
|
| 7 |
+
|
| 8 |
+
client = Prodia()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def run_face_swap(source_image, target_image):
|
| 12 |
+
if source_image is None or target_image is None:
|
| 13 |
+
return
|
| 14 |
+
|
| 15 |
+
print(source_image, target_image)
|
| 16 |
+
|
| 17 |
+
return "https://images.prodia.xyz/acfe8b01-b706-46d9-8c2d-287466337609.png"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def image_to_base64(image: Image):
|
| 21 |
+
# Convert the image to bytes
|
| 22 |
+
buffered = BytesIO()
|
| 23 |
+
image.save(buffered, format="PNG") # You can change format to PNG if needed
|
| 24 |
+
|
| 25 |
+
# Encode the bytes to base64
|
| 26 |
+
img_str = base64.b64encode(buffered.getvalue())
|
| 27 |
+
|
| 28 |
+
return img_str.decode('utf-8') # Convert bytes to string
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
with gr.Column():
|
| 33 |
+
gr.HTML("<h1><center>Face Swap</center></h1>")
|
| 34 |
+
gr.DuplicateButton(size="lg")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column():
|
| 38 |
+
source_image = gr.Image(type="filepath", label="Source Image")
|
| 39 |
+
target_image = gr.Image(type="filepath", label="Target Image")
|
| 40 |
+
with gr.Column():
|
| 41 |
+
run_button = gr.Button("Swap Faces", variant="primary")
|
| 42 |
+
result = gr.Image()
|
| 43 |
+
|
| 44 |
+
run_button.click(fn=run_face_swap, inputs=[source_image, target_image], outputs=result)
|
| 45 |
+
|
| 46 |
+
demo.launch(show_api=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
gradio~=4.28.3
|
| 3 |
+
pillow~=10.2.0
|
| 4 |
+
prodiapy==5.1.2
|
| 5 |
+
requests~=2.31.0
|