Spaces:
ALSv
/
Runtime error

ALSv commited on
Commit
c9e4295
·
verified ·
1 Parent(s): 825cf0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -1,5 +1,5 @@
1
- # -* coding:UTF-8 -*
2
- # !/usr/bin/env python
3
  import numpy as np
4
  import gradio as gr
5
  import roop.globals
@@ -11,22 +11,21 @@ from roop.core import (
11
  )
12
  from roop.processors.frame.core import get_frame_processors_modules
13
  from roop.utilities import normalize_output_path
14
- import os
15
  from PIL import Image
16
 
17
 
18
- def swap_face(source_file, target_file,doFaceEnhancer):
19
-
20
  source_path = "input.jpg"
21
  target_path = "target.jpg"
22
 
 
23
  source_image = Image.fromarray(source_file)
24
  source_image.save(source_path)
25
  target_image = Image.fromarray(target_file)
26
  target_image.save(target_path)
27
 
28
- print("source_path: ", source_path)
29
- print("target_path: ", target_path)
30
 
31
  roop.globals.source_path = source_path
32
  roop.globals.target_path = target_path
@@ -34,10 +33,14 @@ def swap_face(source_file, target_file,doFaceEnhancer):
34
  roop.globals.output_path = normalize_output_path(
35
  roop.globals.source_path, roop.globals.target_path, output_path
36
  )
37
- if doFaceEnhancer == True:
38
- roop.globals.frame_processors = ["face_swapper","face_enhancer"]
 
 
39
  else:
40
  roop.globals.frame_processors = ["face_swapper"]
 
 
41
  roop.globals.headless = True
42
  roop.globals.keep_fps = True
43
  roop.globals.keep_audio = True
@@ -46,7 +49,8 @@ def swap_face(source_file, target_file,doFaceEnhancer):
46
  roop.globals.video_encoder = "libx264"
47
  roop.globals.video_quality = 18
48
  roop.globals.max_memory = suggest_max_memory()
49
- roop.globals.execution_providers = decode_execution_providers(["cuda"])
 
50
  roop.globals.execution_threads = suggest_execution_threads()
51
 
52
  print(
@@ -56,17 +60,25 @@ def swap_face(source_file, target_file,doFaceEnhancer):
56
  roop.globals.output_path,
57
  )
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
  start()
66
  return output_path
67
 
68
 
 
69
  app = gr.Interface(
70
- fn=swap_face, inputs=[gr.Image(), gr.Image(),gr.Checkbox(label="face_enhancer?", info="do face enhancer?")], outputs="image"
 
 
 
 
 
 
71
  )
 
72
  app.launch()
 
1
+ # -*- coding: UTF-8 -*-
2
+ #!/usr/bin/env python
3
  import numpy as np
4
  import gradio as gr
5
  import roop.globals
 
11
  )
12
  from roop.processors.frame.core import get_frame_processors_modules
13
  from roop.utilities import normalize_output_path
 
14
  from PIL import Image
15
 
16
 
17
+ def swap_face(source_file, target_file, doFaceEnhancer):
 
18
  source_path = "input.jpg"
19
  target_path = "target.jpg"
20
 
21
+ # Salva le immagini
22
  source_image = Image.fromarray(source_file)
23
  source_image.save(source_path)
24
  target_image = Image.fromarray(target_file)
25
  target_image.save(target_path)
26
 
27
+ print("source_path:", source_path)
28
+ print("target_path:", target_path)
29
 
30
  roop.globals.source_path = source_path
31
  roop.globals.target_path = target_path
 
33
  roop.globals.output_path = normalize_output_path(
34
  roop.globals.source_path, roop.globals.target_path, output_path
35
  )
36
+
37
+ # Processori
38
+ if doFaceEnhancer:
39
+ roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
40
  else:
41
  roop.globals.frame_processors = ["face_swapper"]
42
+
43
+ # Impostazioni globali
44
  roop.globals.headless = True
45
  roop.globals.keep_fps = True
46
  roop.globals.keep_audio = True
 
49
  roop.globals.video_encoder = "libx264"
50
  roop.globals.video_quality = 18
51
  roop.globals.max_memory = suggest_max_memory()
52
+ # FORZA CPU
53
+ roop.globals.execution_providers = decode_execution_providers(["cpu"])
54
  roop.globals.execution_threads = suggest_execution_threads()
55
 
56
  print(
 
60
  roop.globals.output_path,
61
  )
62
 
63
+ # Controllo pre-processori
64
+ for frame_processor in get_frame_processors_modules(roop.globals.frame_processors):
 
65
  if not frame_processor.pre_check():
66
  return
67
 
68
+ # Avvio roop
69
  start()
70
  return output_path
71
 
72
 
73
+ # Interfaccia Gradio
74
  app = gr.Interface(
75
+ fn=swap_face,
76
+ inputs=[
77
+ gr.Image(label="Source Image"),
78
+ gr.Image(label="Target Image"),
79
+ gr.Checkbox(label="Face Enhancer?", info="Enable face enhancer?")
80
+ ],
81
+ outputs="image"
82
  )
83
+
84
  app.launch()