Spaces:
Runtime error
Runtime error
import gradio as gr | |
import cv2 | |
import numpy as np | |
from PIL import Image | |
import os | |
import warnings | |
# Suppress warnings | |
warnings.filterwarnings('ignore') | |
def create_gui(): | |
# Create the main interface | |
with gr.Blocks(theme=gr.themes.Base( | |
primary_hue=gr.themes.colors.red, | |
font=gr.themes.GoogleFont('Open Sans') | |
)) as interface: | |
gr.Markdown("# FaceFusion") | |
with gr.Tab("Swap"): | |
with gr.Row(): | |
with gr.Column(): | |
source_image = gr.Image(label="Source Face", type="pil") | |
target_image = gr.Image(label="Target Image/Video", type="pil") | |
with gr.Column(): | |
output_image = gr.Image(label="Result") | |
with gr.Row(): | |
process_button = gr.Button("Process", variant="primary") | |
clear_button = gr.Button("Clear") | |
with gr.Tab("Settings"): | |
with gr.Row(): | |
face_detection_threshold = gr.Slider( | |
minimum=0.0, | |
maximum=1.0, | |
value=0.5, | |
step=0.01, | |
label="Face Detection Threshold" | |
) | |
output_quality = gr.Slider( | |
minimum=1, | |
maximum=100, | |
value=90, | |
step=1, | |
label="Output Quality" | |
) | |
with gr.Row(): | |
enable_face_enhancement = gr.Checkbox( | |
label="Enable Face Enhancement", | |
value=True | |
) | |
preserve_original_resolution = gr.Checkbox( | |
label="Preserve Original Resolution", | |
value=True | |
) | |
# Placeholder function for processing | |
def process_images(source, target): | |
# This is where you'd implement the actual face fusion logic | |
# For now, just return the target image | |
return target | |
def clear_outputs(): | |
return None, None, None | |
# Connect the interface elements | |
process_button.click( | |
fn=process_images, | |
inputs=[source_image, target_image], | |
outputs=[output_image] | |
) | |
clear_button.click( | |
fn=clear_outputs, | |
inputs=[], | |
outputs=[source_image, target_image, output_image] | |
) | |
return interface | |
# Create and launch the interface | |
demo = create_gui() | |
# For deployments | |
if __name__ == "__main__": | |
demo.launch() |