Spaces:
Runtime error
Runtime error
Mass
Browse files- app.py +7 -112
- funciones.py +118 -0
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
import time
|
4 |
-
import os
|
5 |
-
import pathlib
|
6 |
import sulkuPypi
|
|
|
7 |
|
8 |
def perform(input1, input2):
|
9 |
|
@@ -11,117 +9,14 @@ def perform(input1, input2):
|
|
11 |
tokens = sulkuPypi.getTokens("gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkABSI6FJrdZDQKk_5lpJOgJoMChxlniw==")
|
12 |
print(f"Tienes: {tokens} tokens. ")
|
13 |
|
14 |
-
#
|
15 |
-
modo = "pic"
|
16 |
-
#local o huggingface
|
17 |
-
plataforma = "huggingface"
|
18 |
-
#face_swapper o face_enhancer o la combinación de ellos.
|
19 |
-
procesador = "face_swapper"
|
20 |
-
|
21 |
-
print(f"Inicio: Estamos en modo {modo}, plataforma: {plataforma} y procesador: {procesador}.")
|
22 |
-
|
23 |
-
path_video = input2
|
24 |
-
print("Path_video es:", path_video)
|
25 |
-
time.sleep(4)
|
26 |
-
|
27 |
-
if modo == "video":
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
path_parts = path_video.split("\\")
|
32 |
-
else:
|
33 |
-
#Para HuggingFace
|
34 |
-
#Creo que no va en imagen.
|
35 |
-
print("La plataforma en la que basaremos la división es HuggingFace.")
|
36 |
-
path_parts = path_video.split("/")
|
37 |
-
|
38 |
-
#Aquí obtendremos nom_video
|
39 |
-
#Creo no va en imagen
|
40 |
-
filename = path_parts[-1]
|
41 |
-
nom_video = filename[:-4]
|
42 |
-
print("Esto es filename alias nom_video: ", nom_video)
|
43 |
-
path_particular = "/".join(path_parts[0:len(path_parts) - 1])
|
44 |
-
path_general = "/".join(path_parts[0:len(path_parts) - 2])
|
45 |
-
path_general = path_general.replace("\\", "/")
|
46 |
-
path_particular = path_particular.replace("\\", "/")
|
47 |
-
print("Path general: ", path_general)
|
48 |
-
print("Path general: ", path_particular)
|
49 |
-
path = pathlib.Path("result.mp4")
|
50 |
-
files = os.listdir(path_general)
|
51 |
-
|
52 |
-
print("Estos son los files que hay:")
|
53 |
-
print(files)
|
54 |
-
|
55 |
-
ext_imagen = "png"
|
56 |
-
ext_video = "mp4"
|
57 |
-
|
58 |
-
#Selector de modo.
|
59 |
-
if modo == "video":
|
60 |
-
print("Se asigno la extensión de video:", ext_video)
|
61 |
-
extension = ext_video
|
62 |
-
else:
|
63 |
-
print("Se asigno la extensión de imagen:", ext_imagen)
|
64 |
-
extension = ext_imagen
|
65 |
|
66 |
-
|
67 |
-
source_path = "source.png"
|
68 |
-
target_path = "target." + extension
|
69 |
-
result_path = "result." + extension
|
70 |
|
71 |
-
#
|
72 |
-
source_image = Image.fromarray(input1)
|
73 |
-
print("Esto es source_image: ", source_image)
|
74 |
-
source_image.save(source_path)
|
75 |
-
|
76 |
-
#Aquí trabajaremos solo el target.
|
77 |
-
if modo == "video":
|
78 |
-
#Para Video
|
79 |
-
target_path = input2
|
80 |
-
else:
|
81 |
-
#Es decir si es modo imagen
|
82 |
-
#Para Imagenes
|
83 |
-
target_image = Image.fromarray(input2)
|
84 |
-
print("Esto es target_image: ", target_image)
|
85 |
-
target_image.save(target_path)
|
86 |
-
|
87 |
-
print("Después de los selectores de modo los paths quedaron así:")
|
88 |
-
print("source_path: ", source_path)
|
89 |
-
print("target_path: ", target_path)
|
90 |
-
|
91 |
-
command = f"python run.py -s {source_path} -t {target_path} -o {result_path} --frame-processor {procesador} --execution-provider cuda"
|
92 |
-
print(command)
|
93 |
-
time.sleep(1)
|
94 |
-
proc = os.popen(command)
|
95 |
-
output = proc.read()
|
96 |
-
|
97 |
-
print("Output (resultado de la ejecución del código):")
|
98 |
-
time.sleep(1)
|
99 |
-
print(output)
|
100 |
-
print("Terminó la impresión del output...")
|
101 |
-
|
102 |
-
print("Éste es el momento en el que se creo result, revisar...")
|
103 |
-
time.sleep(1)
|
104 |
-
|
105 |
-
try:
|
106 |
-
print("Ésta vez no crearemos archivo zip.")
|
107 |
-
|
108 |
-
except Exception as e:
|
109 |
-
# código que se ejecutará si se produce la excepción
|
110 |
-
print(e)
|
111 |
-
|
112 |
-
if modo == "video":
|
113 |
-
#Para video
|
114 |
-
path = pathlib.Path("result.mp4")
|
115 |
-
path_abs = os.path.abspath(path)
|
116 |
-
print("Éste es el path para video:", path)
|
117 |
-
print("Y su ruta absoluta es: ", path_abs)
|
118 |
-
return path
|
119 |
-
else:
|
120 |
-
#Para imagen
|
121 |
-
path = pathlib.Path("result.png")
|
122 |
-
print("Éste es el path para imagen:", path)
|
123 |
-
return path
|
124 |
-
print("Listo! Gracias!")
|
125 |
|
126 |
#Así para imagenes
|
127 |
demo = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
+
|
|
|
|
|
|
|
3 |
import sulkuPypi
|
4 |
+
from funciones import mass
|
5 |
|
6 |
def perform(input1, input2):
|
7 |
|
|
|
9 |
tokens = sulkuPypi.getTokens("gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkABSI6FJrdZDQKk_5lpJOgJoMChxlniw==")
|
10 |
print(f"Tienes: {tokens} tokens. ")
|
11 |
|
12 |
+
#Después autoriza.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
#Después ejecuta la masa.
|
15 |
+
mass(input1,input2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
print("Después de mass imprimo ésto.")
|
|
|
|
|
|
|
18 |
|
19 |
+
#Y finalmente debita los tokens.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
#Así para imagenes
|
22 |
demo = gr.Interface(
|
funciones.py
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
+
import pathlib
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
def mass(input1, input2):
|
7 |
+
|
8 |
+
#video o cualquier otro sería para imagenes.
|
9 |
+
modo = "pic"
|
10 |
+
#local o huggingface
|
11 |
+
plataforma = "huggingface"
|
12 |
+
#face_swapper o face_enhancer o la combinación de ellos.
|
13 |
+
procesador = "face_swapper"
|
14 |
+
|
15 |
+
print(f"Inicio: Estamos en modo {modo}, plataforma: {plataforma} y procesador: {procesador}.")
|
16 |
+
|
17 |
+
path_video = input2
|
18 |
+
print("Path_video es:", path_video)
|
19 |
+
time.sleep(4)
|
20 |
+
|
21 |
+
if modo == "video":
|
22 |
+
|
23 |
+
if plataforma == "local":
|
24 |
+
#Para local.
|
25 |
+
path_parts = path_video.split("\\")
|
26 |
+
else:
|
27 |
+
#Para HuggingFace
|
28 |
+
#Creo que no va en imagen.
|
29 |
+
print("La plataforma en la que basaremos la división es HuggingFace.")
|
30 |
+
path_parts = path_video.split("/")
|
31 |
+
|
32 |
+
#Aquí obtendremos nom_video
|
33 |
+
#Creo no va en imagen
|
34 |
+
filename = path_parts[-1]
|
35 |
+
nom_video = filename[:-4]
|
36 |
+
print("Esto es filename alias nom_video: ", nom_video)
|
37 |
+
path_particular = "/".join(path_parts[0:len(path_parts) - 1])
|
38 |
+
path_general = "/".join(path_parts[0:len(path_parts) - 2])
|
39 |
+
path_general = path_general.replace("\\", "/")
|
40 |
+
path_particular = path_particular.replace("\\", "/")
|
41 |
+
print("Path general: ", path_general)
|
42 |
+
print("Path general: ", path_particular)
|
43 |
+
path = pathlib.Path("result.mp4")
|
44 |
+
files = os.listdir(path_general)
|
45 |
+
|
46 |
+
print("Estos son los files que hay:")
|
47 |
+
print(files)
|
48 |
+
|
49 |
+
ext_imagen = "png"
|
50 |
+
ext_video = "mp4"
|
51 |
+
|
52 |
+
#Selector de modo.
|
53 |
+
if modo == "video":
|
54 |
+
print("Se asigno la extensión de video:", ext_video)
|
55 |
+
extension = ext_video
|
56 |
+
else:
|
57 |
+
print("Se asigno la extensión de imagen:", ext_imagen)
|
58 |
+
extension = ext_imagen
|
59 |
+
|
60 |
+
#El source siempre es una imagen.
|
61 |
+
source_path = "source.png"
|
62 |
+
target_path = "target." + extension
|
63 |
+
result_path = "result." + extension
|
64 |
+
|
65 |
+
#La primera siempre será una imagen, por eso no entra en el modo selector.
|
66 |
+
source_image = Image.fromarray(input1)
|
67 |
+
print("Esto es source_image: ", source_image)
|
68 |
+
source_image.save(source_path)
|
69 |
+
|
70 |
+
#Aquí trabajaremos solo el target.
|
71 |
+
if modo == "video":
|
72 |
+
#Para Video
|
73 |
+
target_path = input2
|
74 |
+
else:
|
75 |
+
#Es decir si es modo imagen
|
76 |
+
#Para Imagenes
|
77 |
+
target_image = Image.fromarray(input2)
|
78 |
+
print("Esto es target_image: ", target_image)
|
79 |
+
target_image.save(target_path)
|
80 |
+
|
81 |
+
print("Después de los selectores de modo los paths quedaron así:")
|
82 |
+
print("source_path: ", source_path)
|
83 |
+
print("target_path: ", target_path)
|
84 |
+
|
85 |
+
command = f"python run.py -s {source_path} -t {target_path} -o {result_path} --frame-processor {procesador} --execution-provider cuda"
|
86 |
+
print(command)
|
87 |
+
time.sleep(1)
|
88 |
+
proc = os.popen(command)
|
89 |
+
output = proc.read()
|
90 |
+
|
91 |
+
print("Output (resultado de la ejecución del código):")
|
92 |
+
time.sleep(1)
|
93 |
+
print(output)
|
94 |
+
print("Terminó la impresión del output...")
|
95 |
+
|
96 |
+
print("Éste es el momento en el que se creo result, revisar...")
|
97 |
+
time.sleep(1)
|
98 |
+
|
99 |
+
try:
|
100 |
+
print("Ésta vez no crearemos archivo zip.")
|
101 |
+
|
102 |
+
except Exception as e:
|
103 |
+
# código que se ejecutará si se produce la excepción
|
104 |
+
print(e)
|
105 |
+
|
106 |
+
if modo == "video":
|
107 |
+
#Para video
|
108 |
+
path = pathlib.Path("result.mp4")
|
109 |
+
path_abs = os.path.abspath(path)
|
110 |
+
print("Éste es el path para video:", path)
|
111 |
+
print("Y su ruta absoluta es: ", path_abs)
|
112 |
+
return path
|
113 |
+
else:
|
114 |
+
#Para imagen
|
115 |
+
path = pathlib.Path("result.png")
|
116 |
+
print("Éste es el path para imagen:", path)
|
117 |
+
return path
|
118 |
+
print("Listo! Gracias!")
|