Spaces:
Runtime error
Runtime error
Upload app
Browse files
app
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import os
|
6 |
+
import warnings
|
7 |
+
|
8 |
+
# Suppress warnings
|
9 |
+
warnings.filterwarnings('ignore')
|
10 |
+
|
11 |
+
def create_gui():
|
12 |
+
# Create the main interface
|
13 |
+
with gr.Blocks(theme=gr.themes.Base(
|
14 |
+
primary_hue=gr.themes.colors.red,
|
15 |
+
font=gr.themes.GoogleFont('Open Sans')
|
16 |
+
)) as interface:
|
17 |
+
gr.Markdown("# FaceFusion")
|
18 |
+
|
19 |
+
with gr.Tab("Swap"):
|
20 |
+
with gr.Row():
|
21 |
+
with gr.Column():
|
22 |
+
source_image = gr.Image(label="Source Face", type="pil")
|
23 |
+
target_image = gr.Image(label="Target Image/Video", type="pil")
|
24 |
+
|
25 |
+
with gr.Column():
|
26 |
+
output_image = gr.Image(label="Result")
|
27 |
+
|
28 |
+
with gr.Row():
|
29 |
+
process_button = gr.Button("Process", variant="primary")
|
30 |
+
clear_button = gr.Button("Clear")
|
31 |
+
|
32 |
+
with gr.Tab("Settings"):
|
33 |
+
with gr.Row():
|
34 |
+
face_detection_threshold = gr.Slider(
|
35 |
+
minimum=0.0,
|
36 |
+
maximum=1.0,
|
37 |
+
value=0.5,
|
38 |
+
step=0.01,
|
39 |
+
label="Face Detection Threshold"
|
40 |
+
)
|
41 |
+
output_quality = gr.Slider(
|
42 |
+
minimum=1,
|
43 |
+
maximum=100,
|
44 |
+
value=90,
|
45 |
+
step=1,
|
46 |
+
label="Output Quality"
|
47 |
+
)
|
48 |
+
|
49 |
+
with gr.Row():
|
50 |
+
enable_face_enhancement = gr.Checkbox(
|
51 |
+
label="Enable Face Enhancement",
|
52 |
+
value=True
|
53 |
+
)
|
54 |
+
preserve_original_resolution = gr.Checkbox(
|
55 |
+
label="Preserve Original Resolution",
|
56 |
+
value=True
|
57 |
+
)
|
58 |
+
|
59 |
+
# Placeholder function for processing
|
60 |
+
def process_images(source, target):
|
61 |
+
# This is where you'd implement the actual face fusion logic
|
62 |
+
# For now, just return the target image
|
63 |
+
return target
|
64 |
+
|
65 |
+
def clear_outputs():
|
66 |
+
return None, None, None
|
67 |
+
|
68 |
+
# Connect the interface elements
|
69 |
+
process_button.click(
|
70 |
+
fn=process_images,
|
71 |
+
inputs=[source_image, target_image],
|
72 |
+
outputs=[output_image]
|
73 |
+
)
|
74 |
+
|
75 |
+
clear_button.click(
|
76 |
+
fn=clear_outputs,
|
77 |
+
inputs=[],
|
78 |
+
outputs=[source_image, target_image, output_image]
|
79 |
+
)
|
80 |
+
|
81 |
+
return interface
|
82 |
+
|
83 |
+
# Create and launch the interface
|
84 |
+
demo = create_gui()
|
85 |
+
|
86 |
+
# For deployments
|
87 |
+
if __name__ == "__main__":
|
88 |
+
demo.launch()
|