Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
|
| 4 |
+
sdxl_client = Client("https://fffiloni-sdxl-dpo.hf.space/--replicas/8llck/")
|
| 5 |
+
faceswap_client = Client("https://tonyassi-face-swap.hf.space/")
|
| 6 |
+
|
| 7 |
+
def infer(portrait_in, prompt_in):
|
| 8 |
+
# Generate Image from SDXL
|
| 9 |
+
gr.Info("Generating SDXL image first ...")
|
| 10 |
+
sdxl_result = sdxl_client.predict(
|
| 11 |
+
prompt_in,
|
| 12 |
+
api_name="/infer"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Face Swap
|
| 16 |
+
gr.Info("Face swap your face on result ...")
|
| 17 |
+
faceswap_result = faceswap_client.predict(
|
| 18 |
+
portrait_in,
|
| 19 |
+
sdxl_result,
|
| 20 |
+
api_name="/predict"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
return faceswap_result
|
| 24 |
+
|
| 25 |
+
css = """
|
| 26 |
+
#col-container{
|
| 27 |
+
margin: 0 auto;
|
| 28 |
+
max-width: 840px;
|
| 29 |
+
}
|
| 30 |
+
"""
|
| 31 |
+
with gr.Blocks(css=css) as demo:
|
| 32 |
+
with gr.Column(elem_id="col-container"):
|
| 33 |
+
gr.HTML("""
|
| 34 |
+
<h2 style="text-align: center;">Portrait Maker</h2>
|
| 35 |
+
""")
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column():
|
| 38 |
+
portrait_in = gr.Image(label="Your face portrait", type="filepath")
|
| 39 |
+
prompt_in = gr.Textbox(label="Prompt to desired portrait using your own face")
|
| 40 |
+
submit_btn = gr.Button("Submit")
|
| 41 |
+
with gr.Column():
|
| 42 |
+
result = gr.Image(label="Result")
|
| 43 |
+
|
| 44 |
+
submit_btn.click(
|
| 45 |
+
fn = infer,
|
| 46 |
+
inputs = [
|
| 47 |
+
portrait_in,
|
| 48 |
+
prompt_in
|
| 49 |
+
],
|
| 50 |
+
outputs = [
|
| 51 |
+
result
|
| 52 |
+
]
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
demo.queue().launch()
|