chukwurah commited on
Commit
49c7285
·
1 Parent(s): 52256ac
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import gradio as gr
 
3
  from roop.core import (
4
  decode_execution_providers,
5
  suggest_max_memory,
@@ -13,7 +14,7 @@ from roop.utilities import normalize_output_path
13
  app = gr.Blocks()
14
 
15
  with app:
16
-
17
  source_image = gr.Image(label="Source Image")
18
  target_images = gr.File(label="Target Images", file_count="multiple")
19
  do_face_enhancer = gr.Checkbox(label="Face Enhancer")
@@ -27,8 +28,15 @@ with app:
27
  for target_image in target_images:
28
  source_path = "input.jpg"
29
  target_path = "target.jpg"
30
- source_image.save(source_path)
31
- target_image.save(target_path)
 
 
 
 
 
 
 
32
  output_path = "output.jpg"
33
  roop.globals.source_path = source_path
34
  roop.globals.target_path = target_path
@@ -37,14 +45,25 @@ with app:
37
  roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
38
  else:
39
  roop.globals.frame_processors = ["face_swapper"]
40
- roop.globals.head_fps = True
 
41
  roop.globals.keep_audio = True
42
  roop.globals.keep_frames = False
43
- roop.globals.video_codec = "libx264"
 
 
 
44
  roop.globals.execution_providers = decode_execution_providers(["cuda"])
45
  roop.globals.execution_threads = suggest_execution_threads()
46
- swap.swap_faces()
47
- result_image = roop.globals.output_path
 
 
 
 
 
 
 
48
  result_images.append(result_image)
49
  return result_images
50
 
 
1
  import os
2
  import gradio as gr
3
+ from PIL import Image
4
  from roop.core import (
5
  decode_execution_providers,
6
  suggest_max_memory,
 
14
  app = gr.Blocks()
15
 
16
  with app:
17
+
18
  source_image = gr.Image(label="Source Image")
19
  target_images = gr.File(label="Target Images", file_count="multiple")
20
  do_face_enhancer = gr.Checkbox(label="Face Enhancer")
 
28
  for target_image in target_images:
29
  source_path = "input.jpg"
30
  target_path = "target.jpg"
31
+
32
+ # Convert gr.Image to PIL Image
33
+ source_pil_image = Image.fromarray(source_image)
34
+ source_pil_image.save(source_path)
35
+
36
+ # Convert gr.File to PIL Image
37
+ target_pil_image = Image.open(target_image.name)
38
+ target_pil_image.save(target_path)
39
+
40
  output_path = "output.jpg"
41
  roop.globals.source_path = source_path
42
  roop.globals.target_path = target_path
 
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
+ for frame_processor in get_frame_processors_modules(
60
+ roop.globals.frame_processors
61
+ ):
62
+ if not frame_processor.pre_check():
63
+ return
64
+
65
+ swap.start()
66
+ result_image = Image.open(roop.globals.output_path)
67
  result_images.append(result_image)
68
  return result_images
69