chukwurah commited on
Commit
9604814
·
1 Parent(s): 38700b7
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -1,11 +1,13 @@
1
  import os
2
  import gradio as gr
3
- import numpy as np
4
- from roop.core import start, decode_execution_providers, suggest_max_memory, suggest_execution_threads
 
 
 
5
  from roop.processors.frame.core import get_frame_processors_modules
6
  from roop.utilities import normalize_output_path
7
-
8
-
9
 
10
 
11
  app = gr.Blocks()
@@ -21,21 +23,34 @@ with app:
21
  history_images = gr.Gallery(label="Processed Images")
22
 
23
  def face_swap(source_image, target_images, do_face_enhancer):
24
- # Your face swap function here
25
- # Assuming you have a function that takes source image, target images, and do_face_enhancer as input and returns a list of result images
26
  result_images = []
27
  for target_image in target_images:
28
- # Call your face swap function for each target image
29
- result_image = face_swap_function(source_image, target_image, do_face_enhancer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  result_images.append(result_image)
31
  return result_images
32
 
33
  gr.Button("Swap Faces").click(face_swap, inputs=[source_image, target_images, do_face_enhancer], outputs=result_images)
34
 
35
  def save_history(result_images):
36
- # Save the result images to a history folder
37
- # You can use a database or a file system to store the images
38
- # For simplicity, let's assume we're using a file system
39
  history_folder = "history"
40
  if not os.path.exists(history_folder):
41
  os.makedirs(history_folder)
 
1
  import os
2
  import gradio as gr
3
+ from roop.core import (
4
+ decode_execution_providers,
5
+ suggest_max_memory,
6
+ suggest_execution_threads,
7
+ )
8
  from roop.processors.frame.core import get_frame_processors_modules
9
  from roop.utilities import normalize_output_path
10
+ from roop import swap
 
11
 
12
 
13
  app = gr.Blocks()
 
23
  history_images = gr.Gallery(label="Processed Images")
24
 
25
  def face_swap(source_image, target_images, do_face_enhancer):
 
 
26
  result_images = []
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
35
+ roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, output_path)
36
+ if do_face_enhancer:
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
 
51
  gr.Button("Swap Faces").click(face_swap, inputs=[source_image, target_images, do_face_enhancer], outputs=result_images)
52
 
53
  def save_history(result_images):
 
 
 
54
  history_folder = "history"
55
  if not os.path.exists(history_folder):
56
  os.makedirs(history_folder)