Moibe commited on
Commit
e756b69
1 Parent(s): 55ad643

Display image as result too

Browse files
Files changed (3) hide show
  1. app.py +33 -16
  2. hasher.py +16 -0
  3. local-filename.jpg +0 -0
app.py CHANGED
@@ -7,7 +7,13 @@ import pathlib
7
  def greet(input1, input2):
8
 
9
  modo = "video"
 
 
 
 
10
  print("Inicio: Estamos en modo ", modo)
 
 
11
 
12
  print("Input1:")
13
  print(input1)
@@ -15,22 +21,35 @@ def greet(input1, input2):
15
  print(input2)
16
 
17
  path_video = input2
18
- #Para local.
19
- #path_parts = path_video.split("\\")
20
- #Para HuggingFace
21
- path_parts = path_video.split("/")
 
 
 
 
 
22
  print("Imprimiendo path_parts: ", path_parts)
23
- path_bueno = "/".join(path_parts[0:len(path_parts) - 2])
24
- #path_bueno = path_bueno.replace("\\", "/")
25
 
26
- print("Path bueno:")
27
- print(path_bueno)
 
28
 
29
- files = os.listdir(path_bueno)
 
 
 
 
 
 
 
30
  print("Estos son los files que hay:")
31
  print(files)
32
 
33
- time.sleep(10)
34
 
35
  ext_imagen = "png"
36
  ext_video = "mp4"
@@ -68,7 +87,7 @@ def greet(input1, input2):
68
  print("source_path: ", source_path)
69
  print("target_path: ", target_path)
70
 
71
- command = f"python run.py -s {source_path} -t {target_path} -o {result_path} --frame-processor face_swapper"
72
  print(command)
73
  time.sleep(1)
74
  proc = os.popen(command)
@@ -80,15 +99,13 @@ def greet(input1, input2):
80
  print("Terminó la impresión del output...")
81
 
82
  print("Ahora estamos imprimiendo las rutas para ver si apareció una nueva:")
83
- files = os.listdir(path_bueno)
84
  print("Estos son los files que hay:")
85
  print(files)
86
 
87
  if modo == "video":
88
  #Para video
89
- path = pathlib.Path("result.mp4")
90
- print("Éste es el path para video:", path)
91
- return path, path
92
  else:
93
  #Para imagen
94
  path = pathlib.Path("result.png")
@@ -102,7 +119,7 @@ def greet(input1, input2):
102
 
103
  #Así para video
104
  demo = gr.Interface(
105
- fn=greet, inputs=[gr.Image(), gr.Video()], outputs=[gr.Video(), gr.Video()]
106
  )
107
 
108
  demo.launch()
 
7
  def greet(input1, input2):
8
 
9
  modo = "video"
10
+ #local o huggingface
11
+ plataforma = "local"
12
+ #face_swapper o face_enhancer o la combinación de ellos.
13
+ procesador = "face_swapper"
14
  print("Inicio: Estamos en modo ", modo)
15
+ print("Estamos en la plataforma:", plataforma)
16
+ print("El procesador es: ", procesador)
17
 
18
  print("Input1:")
19
  print(input1)
 
21
  print(input2)
22
 
23
  path_video = input2
24
+
25
+ if plataforma == "local":
26
+ #Para local.
27
+ path_parts = path_video.split("\\")
28
+ else:
29
+ #Para HuggingFace
30
+ path_parts = path_video.split("/")
31
+
32
+
33
  print("Imprimiendo path_parts: ", path_parts)
34
+ path_particular = "/".join(path_parts[0:len(path_parts) - 1])
35
+ path_general = "/".join(path_parts[0:len(path_parts) - 2])
36
 
37
+
38
+ path_general = path_general.replace("\\", "/")
39
+ path_particular = path_particular.replace("\\", "/")
40
 
41
+ print("Path general: ", path_general)
42
+ print("Path general: ", path_particular)
43
+
44
+ path = pathlib.Path("result.mp4")
45
+ path_foto = pathlib.Path(path_particular + "/temp/whitebeauty/0015.png")
46
+ print("Éste es el path foto: ", path_foto)
47
+
48
+ files = os.listdir(path_general)
49
  print("Estos son los files que hay:")
50
  print(files)
51
 
52
+ time.sleep(5)
53
 
54
  ext_imagen = "png"
55
  ext_video = "mp4"
 
87
  print("source_path: ", source_path)
88
  print("target_path: ", target_path)
89
 
90
+ command = f"python run.py -s {source_path} -t {target_path} -o {result_path} --frame-processor {procesador}"
91
  print(command)
92
  time.sleep(1)
93
  proc = os.popen(command)
 
99
  print("Terminó la impresión del output...")
100
 
101
  print("Ahora estamos imprimiendo las rutas para ver si apareció una nueva:")
102
+ files = os.listdir(path_general)
103
  print("Estos son los files que hay:")
104
  print(files)
105
 
106
  if modo == "video":
107
  #Para video
108
+ return path, path_foto
 
 
109
  else:
110
  #Para imagen
111
  path = pathlib.Path("result.png")
 
119
 
120
  #Así para video
121
  demo = gr.Interface(
122
+ fn=greet, inputs=[gr.Image(), gr.Video()], outputs=[gr.Video(), gr.Image()]
123
  )
124
 
125
  demo.launch()
hasher.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import io
3
+ import os
4
+
5
+ def convert_video_to_base64(filename):
6
+ with open(filename, "rb") as f:
7
+ video_bytes = f.read()
8
+
9
+ base64_string = base64.b64encode(video_bytes)
10
+ return base64_string.decode("utf-8")
11
+
12
+ if __name__ == "__main__":
13
+ filename = "result.mp4"
14
+ base64_string = convert_video_to_base64(filename)
15
+
16
+ print(base64_string)
local-filename.jpg DELETED