import os import time import uuid import gradio as gr from gradio_client import Client hf_token = os.environ.get('HF_TOKEN') sdxl_client = Client("https://fffiloni-sdxl-dpo-2.hf.space/", hf_token=hf_token) faceswap_client = Client("https://fffiloni-deepfakeai.hf.space/", hf_token=hf_token) def get_sdxl(prompt_in): sdxl_result = sdxl_client.predict( prompt_in, api_name="/infer" ) return sdxl_result def infer(portrait_in, prompt_in): # Generate Image from SDXL gr.Info("Generating SDXL image first ...") sdxl_result = get_sdxl(prompt_in) unique_id = str(uuid.uuid4()) # Face Swap gr.Info("Face swap your face on result ...") faceswap_result = faceswap_client.predict( portrait_in, # str (filepath or URL to image) in 'SOURCE IMAGE' Image component sdxl_result, # str (filepath or URL to image) in 'TARGET IMAGE' Image component unique_id, # str in 'parameter_12' Textbox component ["face_swapper", "face_enhancer"], # List[str] in 'FRAME PROCESSORS' Checkboxgroup component "left-right", # str (Option from: ['left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small']) in 'FACE ANALYSER DIRECTION' Dropdown component "none", # str (Option from: ['none', 'reference', 'many']) in 'FACE RECOGNITION' Dropdown component "none", # str (Option from: ['none', 'male', 'female']) in 'FACE ANALYSER GENDER' Dropdown component fn_index=1 ) return faceswap_result css = """ #col-container{ margin: 0 auto; max-width: 840px; } """ with gr.Blocks(css=css) as demo: with gr.Column(elem_id="col-container"): gr.HTML("""
This idea relies to SDXL DPO + DeepFakeAI spaces chained together thanks to the gradio API.
If you want to duplicate this space, you'll need to duplicate both of these privately too in order to make your copy work properly.