import gradio as gr def call_sadtalker_api(source_image, driven_audio, preprocess_type, is_still_mode, enhancer, batch_size, size_of_image, pose_style, facerender, exp_weight, use_ref_video, ref_video, ref_info, use_idle_mode, length_of_audio, blink_every): # Define the API endpoint api_url = "http://localhost:7860/api/predict" # Prepare the payload payload = { "source_image": source_image, "driven_audio": driven_audio, "preprocess_type": preprocess_type, "is_still_mode": is_still_mode, "enhancer": enhancer, "batch_size": batch_size, "size_of_image": size_of_image, "pose_style": pose_style, "facerender": facerender, "exp_weight": exp_weight, "use_ref_video": use_ref_video, "ref_video": ref_video, "ref_info": ref_info, "use_idle_mode": use_idle_mode, "length_of_audio": length_of_audio, "blink_every": blink_every } # Make the API request response = requests.post(api_url, json=payload) result = response.json() # Return the generated video URL return result["data"] # Create the Gradio interface iface = gr.Interface( fn=call_sadtalker_api, inputs=[ gr.Image(type="filepath", label="Source Image"), gr.Audio(type="filepath", label="Driven Audio"), gr.Radio(["crop", "resize", "full", "extcrop", "extfull"], label="Preprocess Type"), gr.Checkbox(label="Still Mode"), gr.Checkbox(label="Enhancer"), gr.Slider(minimum=1, maximum=10, step=1, label="Batch Size"), gr.Radio([256, 512], label="Size of Image"), gr.Slider(minimum=0, maximum=45, step=1, label="Pose Style"), gr.Radio(["facevid2vid", "pirender"], label="Face Render"), gr.Slider(minimum=0, maximum=3, step=0.1, label="Expression Weight"), gr.Checkbox(label="Use Reference Video"), gr.Video(label="Reference Video"), gr.Radio(["pose", "blink", "pose+blink", "all"], label="Reference Info"), gr.Checkbox(label="Use Idle Mode"), gr.Number(label="Length of Audio"), gr.Checkbox(label="Blink Every") ], outputs=gr.Video(label="Generated Video"), title="SadTalker API Client" ) # Launch the interface iface.launch()