Aadhithya commited on
Commit
77a79c3
·
1 Parent(s): 26999cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -4
app.py CHANGED
@@ -1,7 +1,63 @@
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
  import gradio as gr
3
+ import roop.globals
4
+ from roop.core import (
5
+ start,
6
+ decode_execution_providers,
7
+ suggest_max_memory,
8
+ suggest_execution_threads,
9
+ )
10
+ from roop.processors.frame.core import get_frame_processors_modules
11
+ from roop.utilities import normalize_output_path
12
+ import os
13
+ from PIL import Image
14
 
15
+ def swap_face(source_file, target_file):
 
16
 
17
+ source_path = "input.jpg"
18
+ target_path = "target.jpg"
19
+
20
+ source_image = Image.fromarray(source_file)
21
+ source_image.save(source_path)
22
+ target_image = Image.fromarray(target_file)
23
+ target_image.save(target_path)
24
+
25
+ print("source_path: ", source_path)
26
+ print("target_path: ", target_path)
27
+
28
+ roop.globals.source_path = source_path
29
+ roop.globals.target_path = target_path
30
+ output_path = "output.jpg"
31
+ roop.globals.output_path = normalize_output_path(
32
+ roop.globals.source_path, roop.globals.target_path, output_path
33
+ )
34
+ roop.globals.frame_processors = ["face_swapper"]
35
+ roop.globals.headless = True
36
+ roop.globals.keep_fps = True
37
+ roop.globals.keep_audio = True
38
+ roop.globals.keep_frames = False
39
+ roop.globals.many_faces = False
40
+ roop.globals.video_encoder = "libx264"
41
+ roop.globals.video_quality = 18
42
+ roop.globals.max_memory = suggest_max_memory()
43
+ roop.globals.execution_providers = decode_execution_providers(["cpu"])
44
+ roop.globals.execution_threads = suggest_execution_threads()
45
+
46
+ print(
47
+ "start process",
48
+ roop.globals.source_path,
49
+ roop.globals.target_path,
50
+ roop.globals.output_path,
51
+ )
52
+ for frame_processor in get_frame_processors_modules(
53
+ roop.globals.frame_processors
54
+ ):
55
+ if not frame_processor.pre_check():
56
+ return
57
+ start()
58
+ return output_path
59
+
60
+ app = gr.Interface(
61
+ fn=swap_face, inputs=[gr.Image(), gr.Image()], outputs="image"
62
+ )
63
+ app.launch()