Update app.py
Browse files
app.py
CHANGED
@@ -15,35 +15,65 @@ import os
|
|
15 |
from PIL import Image
|
16 |
|
17 |
article_text = """
|
18 |
-
<div style="text-align: center;
|
19 |
-
<
|
20 |
-
<a href="https://www.glossybranding.com/masterclass"
|
21 |
-
background: linear-gradient(45deg, #7B1FA2, #4A148C);
|
22 |
-
color: white;
|
23 |
-
padding: 12px 24px;
|
24 |
-
border-radius: 8px;
|
25 |
-
text-decoration: none;
|
26 |
-
font-weight: bold;
|
27 |
-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
28 |
-
">Schrijf je in voor de AI Masterclass</a>
|
29 |
</div>
|
30 |
"""
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
app = gr.Interface(
|
36 |
-
fn=swap_face,
|
37 |
-
inputs=[
|
38 |
-
gr.Image(label="Upload jouw gezicht"),
|
39 |
-
gr.Image(label="Kies een template afbeelding"),
|
40 |
-
gr.Checkbox(label="Gezicht verbeteren?", info="Aanvinken voor HD-kwaliteit")
|
41 |
-
],
|
42 |
-
outputs=gr.Image(label="Resultaat", show_share_button=True),
|
43 |
-
title="🎭 Glossy Branding AI Face Swap",
|
44 |
-
description="Transformeer jezelf in een AI-kunstwerk! Upload je foto en kies een template.",
|
45 |
-
article=article_text, # 👈 Dit is de cruciale toevoeging
|
46 |
-
theme=gr.themes.Soft(primary_hue="purple")
|
47 |
)
|
48 |
-
|
49 |
app.launch()
|
|
|
15 |
from PIL import Image
|
16 |
|
17 |
article_text = """
|
18 |
+
<div style="text-align: center;">
|
19 |
+
<p>Leer zelf Generative AI-tools te bouwen en te begrijpen!</p>
|
20 |
+
<a href="https://www.glossybranding.com/masterclass">Schrijf je in voor de AI Masterclass</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
</div>
|
22 |
"""
|
23 |
|
24 |
+
|
25 |
+
def swap_face(source_file, target_file,doFaceEnhancer):
|
26 |
+
|
27 |
+
source_path = "input.jpg"
|
28 |
+
target_path = "target.jpg"
|
29 |
+
|
30 |
+
source_image = Image.fromarray(source_file)
|
31 |
+
source_image.save(source_path)
|
32 |
+
target_image = Image.fromarray(target_file)
|
33 |
+
target_image.save(target_path)
|
34 |
+
|
35 |
+
print("source_path: ", source_path)
|
36 |
+
print("target_path: ", target_path)
|
37 |
+
|
38 |
+
roop.globals.source_path = source_path
|
39 |
+
roop.globals.target_path = target_path
|
40 |
+
output_path = "output.jpg"
|
41 |
+
roop.globals.output_path = normalize_output_path(
|
42 |
+
roop.globals.source_path, roop.globals.target_path, output_path
|
43 |
+
)
|
44 |
+
if doFaceEnhancer == True:
|
45 |
+
roop.globals.frame_processors = ["face_swapper","face_enhancer"]
|
46 |
+
else:
|
47 |
+
roop.globals.frame_processors = ["face_swapper"]
|
48 |
+
roop.globals.headless = True
|
49 |
+
roop.globals.keep_fps = True
|
50 |
+
roop.globals.keep_audio = True
|
51 |
+
roop.globals.keep_frames = False
|
52 |
+
roop.globals.many_faces = False
|
53 |
+
roop.globals.video_encoder = "libx264"
|
54 |
+
roop.globals.video_quality = 18
|
55 |
+
roop.globals.max_memory = suggest_max_memory()
|
56 |
+
roop.globals.execution_providers = decode_execution_providers(["cuda"])
|
57 |
+
roop.globals.execution_threads = suggest_execution_threads()
|
58 |
+
|
59 |
+
print(
|
60 |
+
"start process",
|
61 |
+
roop.globals.source_path,
|
62 |
+
roop.globals.target_path,
|
63 |
+
roop.globals.output_path,
|
64 |
+
)
|
65 |
+
|
66 |
+
for frame_processor in get_frame_processors_modules(
|
67 |
+
roop.globals.frame_processors
|
68 |
+
):
|
69 |
+
if not frame_processor.pre_check():
|
70 |
+
return
|
71 |
+
|
72 |
+
start()
|
73 |
+
return output_path
|
74 |
+
|
75 |
|
76 |
app = gr.Interface(
|
77 |
+
fn=swap_face, inputs=[gr.Image(), gr.Image(),gr.Checkbox(label="face_enhancer?", info="do face enhancer?")], outputs="image", article=article_text,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
)
|
|
|
79 |
app.launch()
|