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