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