chukwurah commited on
Commit
3a2c844
·
1 Parent(s): e152316
Files changed (1) hide show
  1. app.py +46 -48
app.py CHANGED
@@ -12,57 +12,51 @@ from roop.utilities import normalize_output_path
12
  import os
13
  from PIL import Image
14
 
 
15
 
16
- def swap_face(source_file, target_file, doFaceEnhancer):
17
-
18
  source_path = "input.jpg"
19
- target_path = "target.jpg"
20
-
21
  source_image = Image.fromarray(source_file)
22
  source_image.save(source_path)
23
- target_image = Image.fromarray(target_file)
24
- target_image.save(target_path)
25
-
26
- print("source_path: ", source_path)
27
- print("target_path: ", target_path)
28
 
29
- roop.globals.source_path = source_path
30
- roop.globals.target_path = target_path
31
- output_path = "output.jpg"
32
- roop.globals.output_path = normalize_output_path(
33
- roop.globals.source_path, roop.globals.target_path, output_path
34
- )
35
- if doFaceEnhancer:
36
- roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
37
- else:
38
- roop.globals.frame_processors = ["face_swapper"]
39
- roop.globals.headless = True
40
- roop.globals.keep_fps = True
41
- roop.globals.keep_audio = True
42
- roop.globals.keep_frames = False
43
- roop.globals.many_faces = False
44
- roop.globals.video_encoder = "libx264"
45
- roop.globals.video_quality = 18
46
- roop.globals.max_memory = suggest_max_memory()
47
- roop.globals.execution_providers = decode_execution_providers(["cuda"])
48
- roop.globals.execution_threads = suggest_execution_threads()
49
 
50
- print(
51
- "start process",
52
- roop.globals.source_path,
53
- roop.globals.target_path,
54
- roop.globals.output_path,
55
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- for frame_processor in get_frame_processors_modules(
58
- roop.globals.frame_processors
59
- ):
60
- if not frame_processor.pre_check():
61
- return
62
 
63
- start()
64
- return output_path
 
65
 
 
66
 
67
  html_section_1 = "<div><h1>Welcome to the Face Swap App</h1></div>"
68
  html_section_2 = '<div><p>Upload your source and target images to swap faces. Optionally, use the face enhancer feature for HD Results.</p><h2><br /><strong>For fast and bulk Swap:</strong>&nbsp;<a href="https://picfy.xyz/" target="_blank" rel="noopener">https://picfy.xyz/</a><br /> <strong>Support me USDT (TRC-20): TAe7hsSVWtMEYz3G5V1UiUdYPQVqm28bKx</h2></div>'
@@ -72,10 +66,14 @@ app = gr.Blocks()
72
  with app:
73
  gr.HTML(html_section_1)
74
  gr.HTML(html_section_2)
75
- gr.Interface(
76
- fn=swap_face,
77
- inputs=[gr.Image(), gr.Image(), gr.Checkbox(label="face_enhancer?", info="do face enhancer?")],
78
- outputs="image"
79
- )
 
 
 
 
80
 
81
- app.launch()
 
12
  import os
13
  from PIL import Image
14
 
15
+ processed_images = []
16
 
17
+ def swap_face(source_file, target_files, doFaceEnhancer):
 
18
  source_path = "input.jpg"
 
 
19
  source_image = Image.fromarray(source_file)
20
  source_image.save(source_path)
 
 
 
 
 
21
 
22
+ results = []
23
+ for i, target_file in enumerate(target_files):
24
+ target_path = f"target_{i}.jpg"
25
+ target_image = Image.fromarray(target_file)
26
+ target_image.save(target_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ roop.globals.source_path = source_path
29
+ roop.globals.target_path = target_path
30
+ output_path = f"output_{i}.jpg"
31
+ roop.globals.output_path = normalize_output_path(
32
+ roop.globals.source_path, roop.globals.target_path, output_path
33
+ )
34
+ if doFaceEnhancer:
35
+ roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
36
+ else:
37
+ roop.globals.frame_processors = ["face_swapper"]
38
+ roop.globals.headless = True
39
+ roop.globals.keep_fps = True
40
+ roop.globals.keep_audio = True
41
+ roop.globals.keep_frames = False
42
+ roop.globals.many_faces = False
43
+ roop.globals.video_encoder = "libx264"
44
+ roop.globals.video_quality = 18
45
+ roop.globals.max_memory = suggest_max_memory()
46
+ roop.globals.execution_providers = decode_execution_providers(["cuda"])
47
+ roop.globals.execution_threads = suggest_execution_threads()
48
 
49
+ for frame_processor in get_frame_processors_modules(
50
+ roop.globals.frame_processors
51
+ ):
52
+ if not frame_processor.pre_check():
53
+ return
54
 
55
+ start()
56
+ results.append(output_path)
57
+ processed_images.append(output_path)
58
 
59
+ return results
60
 
61
  html_section_1 = "<div><h1>Welcome to the Face Swap App</h1></div>"
62
  html_section_2 = '<div><p>Upload your source and target images to swap faces. Optionally, use the face enhancer feature for HD Results.</p><h2><br /><strong>For fast and bulk Swap:</strong>&nbsp;<a href="https://picfy.xyz/" target="_blank" rel="noopener">https://picfy.xyz/</a><br /> <strong>Support me USDT (TRC-20): TAe7hsSVWtMEYz3G5V1UiUdYPQVqm28bKx</h2></div>'
 
66
  with app:
67
  gr.HTML(html_section_1)
68
  gr.HTML(html_section_2)
69
+ with gr.Tabs():
70
+ with gr.TabItem("Face Swap"):
71
+ gr.Interface(
72
+ fn=swap_face,
73
+ inputs=[gr.Image(), gr.Image(type="numpy", label="Target Images", multiple=True), gr.Checkbox(label="face_enhancer?", info="do face enhancer?")],
74
+ outputs=gr.Gallery(label="Processed Images")
75
+ )
76
+ with gr.TabItem("History"):
77
+ gr.Gallery(value=processed_images, label="Processed Images History")
78
 
79
+ app.launch()