Spaces:
Runtime error
Runtime error
Moibe
commited on
Commit
•
6d83a58
1
Parent(s):
feb9e51
Day Done
Browse files- app.py +4 -22
- auth.py +10 -28
- batcher.py +0 -2
- frameFixer.py +1 -2
- roop/utilities.py +195 -199
- sulkuPypi.py +113 -130
- tools.py +4 -9
app.py
CHANGED
@@ -1,33 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
import sulkuPypi
|
3 |
from funciones import mass
|
4 |
-
from data import usuarios
|
5 |
-
import time
|
6 |
-
import nycklar.nodes
|
7 |
import tools
|
8 |
import auth
|
9 |
-
import ast
|
10 |
|
11 |
#Funciones
|
12 |
|
13 |
#Función principal
|
14 |
def perform(input1, input2, request: gr.Request):
|
15 |
|
16 |
-
print("5.- Entré a Perform, checando persistencia...")
|
17 |
-
|
18 |
tokens = sulkuPypi.getTokens(sulkuPypi.encripta(request.username).decode("utf-8")) #Todo en una línea.
|
19 |
-
|
20 |
-
|
21 |
#Después autoriza.
|
22 |
#Si está autorizada puede ejecutar la tarea, ésta lógica si está a cargo aquí, por parte de la app y su desarrollador, no de Sulku.
|
23 |
-
|
24 |
autorizacion = sulkuPypi.authorize(gr.State.tokens, 'picswap')
|
25 |
print("La autorización es: ", autorizacion)
|
26 |
|
27 |
-
if autorizacion is True:
|
28 |
-
|
29 |
path = mass(input1,input2)
|
30 |
-
|
31 |
else:
|
32 |
info_window = "Out of credits..."
|
33 |
path = 'no-credits.png'
|
@@ -75,7 +65,6 @@ source_image = gr.Image(label="Source")
|
|
75 |
destination_image = gr.Image(label="Destination")
|
76 |
|
77 |
#Outputs
|
78 |
-
print("1.- Entré en app.py...")
|
79 |
creditos = None
|
80 |
result_image = gr.Image(label="Blend Result")
|
81 |
txt_credits = gr.Textbox(label="Credits Available", value="", interactive=False)
|
@@ -83,21 +72,14 @@ html_credits = gr.HTML()
|
|
83 |
lbl_console = gr.Label(label="AI Terminal Messages", value="AI Engine ready...", container=True)
|
84 |
btn_buy = gr.Button("Buy More", visible=False, size='lg')
|
85 |
|
86 |
-
#valor = gr.State.tokens
|
87 |
-
valor = ""
|
88 |
-
|
89 |
with gr.Blocks(theme=gr.themes.Base(), css="footer {visibility: hidden}") as main:
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
#Función, input, output
|
94 |
main.load(display_tokens, None, html_credits)
|
95 |
|
96 |
with gr.Row():
|
97 |
-
|
98 |
demo = gr.Interface(
|
99 |
fn=perform,
|
100 |
-
title="",
|
101 |
inputs=[source_image, destination_image],
|
102 |
outputs=[result_image, lbl_console, html_credits, btn_buy],
|
103 |
allow_flagging='never'
|
|
|
1 |
import gradio as gr
|
2 |
import sulkuPypi
|
3 |
from funciones import mass
|
|
|
|
|
|
|
4 |
import tools
|
5 |
import auth
|
|
|
6 |
|
7 |
#Funciones
|
8 |
|
9 |
#Función principal
|
10 |
def perform(input1, input2, request: gr.Request):
|
11 |
|
|
|
|
|
12 |
tokens = sulkuPypi.getTokens(sulkuPypi.encripta(request.username).decode("utf-8")) #Todo en una línea.
|
13 |
+
|
|
|
14 |
#Después autoriza.
|
15 |
#Si está autorizada puede ejecutar la tarea, ésta lógica si está a cargo aquí, por parte de la app y su desarrollador, no de Sulku.
|
|
|
16 |
autorizacion = sulkuPypi.authorize(gr.State.tokens, 'picswap')
|
17 |
print("La autorización es: ", autorizacion)
|
18 |
|
19 |
+
if autorizacion is True:
|
|
|
20 |
path = mass(input1,input2)
|
|
|
21 |
else:
|
22 |
info_window = "Out of credits..."
|
23 |
path = 'no-credits.png'
|
|
|
65 |
destination_image = gr.Image(label="Destination")
|
66 |
|
67 |
#Outputs
|
|
|
68 |
creditos = None
|
69 |
result_image = gr.Image(label="Blend Result")
|
70 |
txt_credits = gr.Textbox(label="Credits Available", value="", interactive=False)
|
|
|
72 |
lbl_console = gr.Label(label="AI Terminal Messages", value="AI Engine ready...", container=True)
|
73 |
btn_buy = gr.Button("Buy More", visible=False, size='lg')
|
74 |
|
|
|
|
|
|
|
75 |
with gr.Blocks(theme=gr.themes.Base(), css="footer {visibility: hidden}") as main:
|
76 |
+
|
77 |
+
#Cargado en Load, Función, input, output
|
|
|
|
|
78 |
main.load(display_tokens, None, html_credits)
|
79 |
|
80 |
with gr.Row():
|
|
|
81 |
demo = gr.Interface(
|
82 |
fn=perform,
|
|
|
83 |
inputs=[source_image, destination_image],
|
84 |
outputs=[result_image, lbl_console, html_credits, btn_buy],
|
85 |
allow_flagging='never'
|
auth.py
CHANGED
@@ -1,47 +1,29 @@
|
|
1 |
#from data import usuarios
|
2 |
import gradio as gr
|
3 |
import sulkuPypi
|
4 |
-
import time
|
5 |
import ast
|
6 |
|
7 |
-
def authenticate(username, password)
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
#Future: Obten el dict usuarios desde la API no localmente en ésta app.
|
12 |
-
cadena_usuarios = sulkuPypi.getData()
|
13 |
-
|
14 |
-
# Convertir la cadena en una lista de tuplas
|
15 |
-
print("Ahora voy a convertir la cadena de usuarios en una lista: ")
|
16 |
lista_usuarios = ast.literal_eval(cadena_usuarios)
|
17 |
|
18 |
-
for u, p
|
19 |
#Si el usuario y la contraseña son correctas...
|
20 |
if username == u and password == p:
|
21 |
-
#
|
22 |
-
|
23 |
-
#Bienvenida al usuario...
|
24 |
-
print("Welcome 182:", gr.State.usuario)
|
25 |
-
if f == "new":
|
26 |
-
print("Usuario Nuevo...")
|
27 |
-
else:
|
28 |
-
print("Usuario Normal...")
|
29 |
|
30 |
#Capsule es el usuario encriptado que enviarás a la API de Sulku.
|
31 |
#El encriptador ahora será parte de Sulku, porque es una herramienta que se requiere para...
|
32 |
#...las comunicaciones con Sulku.
|
33 |
-
|
34 |
-
|
35 |
-
gr.State.capsule = capsule
|
36 |
-
|
37 |
#Checa cuantos tokens tiene ese usuario via la API de Sulku:
|
38 |
#FUTURE: Checa si vale la pena guardar éstos estados.
|
39 |
gr.State.tokens = sulkuPypi.getTokens(capsule)
|
40 |
-
|
41 |
-
print(f"Tienes: {gr.State.tokens} tokens. ")
|
42 |
-
creditos = gr.State.tokens
|
43 |
-
print(f"Ésta es la cantidad guardada en creditos: {creditos}")
|
44 |
-
|
45 |
return True
|
46 |
|
47 |
#Si no hubo coincidencia regresas un false.
|
|
|
1 |
#from data import usuarios
|
2 |
import gradio as gr
|
3 |
import sulkuPypi
|
|
|
4 |
import ast
|
5 |
|
6 |
+
def authenticate(username, password):
|
7 |
+
#Future: Obten el dict usuarios desde la API no localmente en ésta app. OK!
|
8 |
+
cadena_usuarios = sulkuPypi.getData()
|
9 |
+
#Convertir la cadena en una lista de tuplas
|
|
|
|
|
|
|
|
|
|
|
10 |
lista_usuarios = ast.literal_eval(cadena_usuarios)
|
11 |
|
12 |
+
for u, p in lista_usuarios:
|
13 |
#Si el usuario y la contraseña son correctas...
|
14 |
if username == u and password == p:
|
15 |
+
#Future: Considerar que a más usuarios, más se tardará en repasar ésta lista.
|
16 |
+
#Future, pensar como se va a corelacionar con login via Firebase.
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
#Capsule es el usuario encriptado que enviarás a la API de Sulku.
|
19 |
#El encriptador ahora será parte de Sulku, porque es una herramienta que se requiere para...
|
20 |
#...las comunicaciones con Sulku.
|
21 |
+
capsule = sulkuPypi.encripta(username).decode("utf-8") #decode es para quitarle el 'b
|
22 |
+
|
|
|
|
|
23 |
#Checa cuantos tokens tiene ese usuario via la API de Sulku:
|
24 |
#FUTURE: Checa si vale la pena guardar éstos estados.
|
25 |
gr.State.tokens = sulkuPypi.getTokens(capsule)
|
26 |
+
|
|
|
|
|
|
|
|
|
27 |
return True
|
28 |
|
29 |
#Si no hubo coincidencia regresas un false.
|
batcher.py
CHANGED
@@ -6,7 +6,6 @@ pics_dir = "D:/Organizar/ZJB/Esyle/art"
|
|
6 |
#pics_dir = "D:/Esyle-Prod/videos/next"
|
7 |
pics_name = os.path.basename(pics_dir)
|
8 |
print(pics_name)
|
9 |
-
time.sleep(1)
|
10 |
|
11 |
#Crea un nuevo directorio dentro de resultados-pics que contendrá los resultados de éste batch.
|
12 |
resultados_dir = "D:/Esyle-Prod/resultados_pics/"
|
@@ -27,7 +26,6 @@ for pic in pics:
|
|
27 |
print("Listo para correr el comando, nos faltan: ", cuantos)
|
28 |
command = "python run.py -s D:/Esyle-Prod/fotos/irina.jpg -t " + pics_dir + "/" + pic + " -o " + resultados_dir + pics_name + "/irina-" + pic + " --frame-processor face_swapper"
|
29 |
print(command)
|
30 |
-
time.sleep(1)
|
31 |
proc = os.popen(command)
|
32 |
output = proc.read()
|
33 |
cuantos -= 1
|
|
|
6 |
#pics_dir = "D:/Esyle-Prod/videos/next"
|
7 |
pics_name = os.path.basename(pics_dir)
|
8 |
print(pics_name)
|
|
|
9 |
|
10 |
#Crea un nuevo directorio dentro de resultados-pics que contendrá los resultados de éste batch.
|
11 |
resultados_dir = "D:/Esyle-Prod/resultados_pics/"
|
|
|
26 |
print("Listo para correr el comando, nos faltan: ", cuantos)
|
27 |
command = "python run.py -s D:/Esyle-Prod/fotos/irina.jpg -t " + pics_dir + "/" + pic + " -o " + resultados_dir + pics_name + "/irina-" + pic + " --frame-processor face_swapper"
|
28 |
print(command)
|
|
|
29 |
proc = os.popen(command)
|
30 |
output = proc.read()
|
31 |
cuantos -= 1
|
frameFixer.py
CHANGED
@@ -69,8 +69,7 @@ def frameFixer(video):
|
|
69 |
# Si el número del archivo no coincide con el contador, significa que hay un número faltante
|
70 |
print("Archivo y contador diferente:")
|
71 |
print(f"Falta el archivo {i}.png.")
|
72 |
-
|
73 |
-
|
74 |
archivo_faltante = i
|
75 |
#Aquí empieza el proceso de crear el nombre del duplicador:
|
76 |
# Convertimos la variable a string
|
|
|
69 |
# Si el número del archivo no coincide con el contador, significa que hay un número faltante
|
70 |
print("Archivo y contador diferente:")
|
71 |
print(f"Falta el archivo {i}.png.")
|
72 |
+
|
|
|
73 |
archivo_faltante = i
|
74 |
#Aquí empieza el proceso de crear el nombre del duplicador:
|
75 |
# Convertimos la variable a string
|
roop/utilities.py
CHANGED
@@ -1,199 +1,195 @@
|
|
1 |
-
import sys
|
2 |
-
import time
|
3 |
-
import glob
|
4 |
-
import mimetypes
|
5 |
-
import os
|
6 |
-
import platform
|
7 |
-
import shutil
|
8 |
-
import ssl
|
9 |
-
import subprocess
|
10 |
-
import urllib
|
11 |
-
from pathlib import Path
|
12 |
-
from typing import List, Optional
|
13 |
-
from tqdm import tqdm
|
14 |
-
|
15 |
-
import roop.globals
|
16 |
-
|
17 |
-
TEMP_DIRECTORY = 'temp'
|
18 |
-
TEMP_VIDEO_FILE = 'temp.mp4'
|
19 |
-
|
20 |
-
# monkey patch ssl for mac
|
21 |
-
if platform.system().lower() == 'darwin':
|
22 |
-
ssl._create_default_https_context = ssl._create_unverified_context
|
23 |
-
|
24 |
-
|
25 |
-
def run_ffmpeg(args: List[str]) -> bool:
|
26 |
-
print("MOI: Entré a run_ffmpeg...")
|
27 |
-
commands = ['ffmpeg', '-hide_banner', '-loglevel', roop.globals.log_level]
|
28 |
-
commands.extend(args)
|
29 |
-
try:
|
30 |
-
print("MOI: Estoy en el try del subproceso.")
|
31 |
-
subprocess.check_output(commands, stderr=subprocess.STDOUT)
|
32 |
-
return True
|
33 |
-
except Exception:
|
34 |
-
print("Moi: Imprimiendo el error...")
|
35 |
-
print(sys.exc_info()[0])
|
36 |
-
pass
|
37 |
-
return False
|
38 |
-
|
39 |
-
|
40 |
-
def detect_fps(target_path: str) -> float:
|
41 |
-
command = ['ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=r_frame_rate', '-of', 'default=noprint_wrappers=1:nokey=1', target_path]
|
42 |
-
output = subprocess.check_output(command).decode().strip().split('/')
|
43 |
-
try:
|
44 |
-
numerator, denominator = map(int, output)
|
45 |
-
return numerator / denominator
|
46 |
-
except Exception:
|
47 |
-
pass
|
48 |
-
return 30
|
49 |
-
|
50 |
-
|
51 |
-
def extract_frames(target_path: str, fps: float = 30) -> bool:
|
52 |
-
temp_directory_path = get_temp_directory_path(target_path)
|
53 |
-
temp_frame_quality = roop.globals.temp_frame_quality * 31 // 100
|
54 |
-
return run_ffmpeg(['-hwaccel', 'auto', '-i', target_path, '-q:v', str(temp_frame_quality), '-pix_fmt', 'rgb24', '-vf', 'fps=' + str(fps), os.path.join(temp_directory_path, '%04d.' + roop.globals.temp_frame_format)])
|
55 |
-
|
56 |
-
|
57 |
-
def create_video(target_path: str, fps: float = 30) -> bool:
|
58 |
-
temp_output_path = get_temp_output_path(target_path)
|
59 |
-
temp_directory_path = get_temp_directory_path(target_path)
|
60 |
-
output_video_quality = (roop.globals.output_video_quality + 1) * 51 // 100
|
61 |
-
commands = ['-hwaccel', 'auto', '-r', str(fps), '-i', os.path.join(temp_directory_path, '%04d.' + roop.globals.temp_frame_format), '-c:v', roop.globals.output_video_encoder]
|
62 |
-
if roop.globals.output_video_encoder in ['libx264', 'libx265', 'libvpx']:
|
63 |
-
commands.extend(['-crf', str(output_video_quality)])
|
64 |
-
if roop.globals.output_video_encoder in ['h264_nvenc', 'hevc_nvenc']:
|
65 |
-
commands.extend(['-cq', str(output_video_quality)])
|
66 |
-
commands.extend(['-pix_fmt', 'yuv420p', '-vf', 'colorspace=bt709:iall=bt601-6-625:fast=1', '-y', temp_output_path])
|
67 |
-
|
68 |
-
print("Y así quedan los commands:", commands)
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
#
|
74 |
-
|
75 |
-
#
|
76 |
-
|
77 |
-
|
78 |
-
#
|
79 |
-
|
80 |
-
|
81 |
-
#
|
82 |
-
|
83 |
-
#
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
print("
|
92 |
-
|
93 |
-
print("
|
94 |
-
|
95 |
-
print("
|
96 |
-
temp_output_path
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
print(
|
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 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
def
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
def resolve_relative_path(path: str) -> str:
|
199 |
-
return os.path.abspath(os.path.join(os.path.dirname(__file__), path))
|
|
|
1 |
+
import sys
|
2 |
+
import time
|
3 |
+
import glob
|
4 |
+
import mimetypes
|
5 |
+
import os
|
6 |
+
import platform
|
7 |
+
import shutil
|
8 |
+
import ssl
|
9 |
+
import subprocess
|
10 |
+
import urllib
|
11 |
+
from pathlib import Path
|
12 |
+
from typing import List, Optional
|
13 |
+
from tqdm import tqdm
|
14 |
+
|
15 |
+
import roop.globals
|
16 |
+
|
17 |
+
TEMP_DIRECTORY = 'temp'
|
18 |
+
TEMP_VIDEO_FILE = 'temp.mp4'
|
19 |
+
|
20 |
+
# monkey patch ssl for mac
|
21 |
+
if platform.system().lower() == 'darwin':
|
22 |
+
ssl._create_default_https_context = ssl._create_unverified_context
|
23 |
+
|
24 |
+
|
25 |
+
def run_ffmpeg(args: List[str]) -> bool:
|
26 |
+
print("MOI: Entré a run_ffmpeg...")
|
27 |
+
commands = ['ffmpeg', '-hide_banner', '-loglevel', roop.globals.log_level]
|
28 |
+
commands.extend(args)
|
29 |
+
try:
|
30 |
+
print("MOI: Estoy en el try del subproceso.")
|
31 |
+
subprocess.check_output(commands, stderr=subprocess.STDOUT)
|
32 |
+
return True
|
33 |
+
except Exception:
|
34 |
+
print("Moi: Imprimiendo el error...")
|
35 |
+
print(sys.exc_info()[0])
|
36 |
+
pass
|
37 |
+
return False
|
38 |
+
|
39 |
+
|
40 |
+
def detect_fps(target_path: str) -> float:
|
41 |
+
command = ['ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=r_frame_rate', '-of', 'default=noprint_wrappers=1:nokey=1', target_path]
|
42 |
+
output = subprocess.check_output(command).decode().strip().split('/')
|
43 |
+
try:
|
44 |
+
numerator, denominator = map(int, output)
|
45 |
+
return numerator / denominator
|
46 |
+
except Exception:
|
47 |
+
pass
|
48 |
+
return 30
|
49 |
+
|
50 |
+
|
51 |
+
def extract_frames(target_path: str, fps: float = 30) -> bool:
|
52 |
+
temp_directory_path = get_temp_directory_path(target_path)
|
53 |
+
temp_frame_quality = roop.globals.temp_frame_quality * 31 // 100
|
54 |
+
return run_ffmpeg(['-hwaccel', 'auto', '-i', target_path, '-q:v', str(temp_frame_quality), '-pix_fmt', 'rgb24', '-vf', 'fps=' + str(fps), os.path.join(temp_directory_path, '%04d.' + roop.globals.temp_frame_format)])
|
55 |
+
|
56 |
+
|
57 |
+
def create_video(target_path: str, fps: float = 30) -> bool:
|
58 |
+
temp_output_path = get_temp_output_path(target_path)
|
59 |
+
temp_directory_path = get_temp_directory_path(target_path)
|
60 |
+
output_video_quality = (roop.globals.output_video_quality + 1) * 51 // 100
|
61 |
+
commands = ['-hwaccel', 'auto', '-r', str(fps), '-i', os.path.join(temp_directory_path, '%04d.' + roop.globals.temp_frame_format), '-c:v', roop.globals.output_video_encoder]
|
62 |
+
if roop.globals.output_video_encoder in ['libx264', 'libx265', 'libvpx']:
|
63 |
+
commands.extend(['-crf', str(output_video_quality)])
|
64 |
+
if roop.globals.output_video_encoder in ['h264_nvenc', 'hevc_nvenc']:
|
65 |
+
commands.extend(['-cq', str(output_video_quality)])
|
66 |
+
commands.extend(['-pix_fmt', 'yuv420p', '-vf', 'colorspace=bt709:iall=bt601-6-625:fast=1', '-y', temp_output_path])
|
67 |
+
|
68 |
+
print("Y así quedan los commands:", commands)
|
69 |
+
print("MOI: Y se supone que aquí estará a punto de crear el video:")
|
70 |
+
|
71 |
+
# while True:
|
72 |
+
# # Imprime un mensaje
|
73 |
+
# print("Pulsa la tecla Y para hacer el video...")
|
74 |
+
|
75 |
+
# # Espera un segundo
|
76 |
+
# time.sleep(1)
|
77 |
+
|
78 |
+
# # Lee un carácter de la entrada estándar
|
79 |
+
# key = input()
|
80 |
+
|
81 |
+
# # Si se presiona la tecla Y, sale del bucle
|
82 |
+
# if key == "Y":
|
83 |
+
# break
|
84 |
+
|
85 |
+
return run_ffmpeg(commands)
|
86 |
+
|
87 |
+
|
88 |
+
def restore_audio(target_path: str, output_path: str) -> None:
|
89 |
+
print("MOI: Estamos en restore_audio...")
|
90 |
+
print("Los parámetros recibidos son:")
|
91 |
+
print("target_path:", target_path)
|
92 |
+
time.sleep(1)
|
93 |
+
print("output_path:", output_path)
|
94 |
+
temp_output_path = get_temp_output_path(target_path)
|
95 |
+
print("MOI: Éste es el temp_output_path, es audio o video?:")
|
96 |
+
print(temp_output_path)
|
97 |
+
|
98 |
+
try:
|
99 |
+
args = ['-i', temp_output_path, '-i', target_path, '-c:v', 'copy', '-map', '0:v:0', '-map', '1:a:0', '-y', output_path]
|
100 |
+
print("Estos son los args de audio:")
|
101 |
+
print(args)
|
102 |
+
time.sleep(10)
|
103 |
+
done = run_ffmpeg(args)
|
104 |
+
#done = run_ffmpeg(['-i', temp_output_path, '-i', target_path, '-c:v', 'copy', '-map', '0:v:0', '-map', '1:a:0', '-y', output_path])
|
105 |
+
|
106 |
+
except:
|
107 |
+
print("Ocurrió un error")
|
108 |
+
print(sys.exc_info()[0])
|
109 |
+
|
110 |
+
if not done:
|
111 |
+
move_temp(target_path, output_path)
|
112 |
+
print("Entre a not done :(")
|
113 |
+
print("Terminé audio...")
|
114 |
+
time.sleep(3)
|
115 |
+
|
116 |
+
|
117 |
+
def get_temp_frame_paths(target_path: str) -> List[str]:
|
118 |
+
temp_directory_path = get_temp_directory_path(target_path)
|
119 |
+
return glob.glob((os.path.join(glob.escape(temp_directory_path), '*.' + roop.globals.temp_frame_format)))
|
120 |
+
|
121 |
+
|
122 |
+
def get_temp_directory_path(target_path: str) -> str:
|
123 |
+
target_name, _ = os.path.splitext(os.path.basename(target_path))
|
124 |
+
target_directory_path = os.path.dirname(target_path)
|
125 |
+
return os.path.join(target_directory_path, TEMP_DIRECTORY, target_name)
|
126 |
+
|
127 |
+
|
128 |
+
def get_temp_output_path(target_path: str) -> str:
|
129 |
+
temp_directory_path = get_temp_directory_path(target_path)
|
130 |
+
return os.path.join(temp_directory_path, TEMP_VIDEO_FILE)
|
131 |
+
|
132 |
+
|
133 |
+
def normalize_output_path(source_path: str, target_path: str, output_path: str) -> Optional[str]:
|
134 |
+
if source_path and target_path and output_path:
|
135 |
+
source_name, _ = os.path.splitext(os.path.basename(source_path))
|
136 |
+
target_name, target_extension = os.path.splitext(os.path.basename(target_path))
|
137 |
+
if os.path.isdir(output_path):
|
138 |
+
return os.path.join(output_path, source_name + '-' + target_name + target_extension)
|
139 |
+
return output_path
|
140 |
+
|
141 |
+
|
142 |
+
def create_temp(target_path: str) -> None:
|
143 |
+
temp_directory_path = get_temp_directory_path(target_path)
|
144 |
+
Path(temp_directory_path).mkdir(parents=True, exist_ok=True)
|
145 |
+
|
146 |
+
|
147 |
+
def move_temp(target_path: str, output_path: str) -> None:
|
148 |
+
temp_output_path = get_temp_output_path(target_path)
|
149 |
+
if os.path.isfile(temp_output_path):
|
150 |
+
if os.path.isfile(output_path):
|
151 |
+
os.remove(output_path)
|
152 |
+
shutil.move(temp_output_path, output_path)
|
153 |
+
|
154 |
+
|
155 |
+
def clean_temp(target_path: str) -> None:
|
156 |
+
temp_directory_path = get_temp_directory_path(target_path)
|
157 |
+
parent_directory_path = os.path.dirname(temp_directory_path)
|
158 |
+
if not roop.globals.keep_frames and os.path.isdir(temp_directory_path):
|
159 |
+
shutil.rmtree(temp_directory_path)
|
160 |
+
if os.path.exists(parent_directory_path) and not os.listdir(parent_directory_path):
|
161 |
+
os.rmdir(parent_directory_path)
|
162 |
+
|
163 |
+
|
164 |
+
def has_image_extension(image_path: str) -> bool:
|
165 |
+
return image_path.lower().endswith(('png', 'jpg', 'jpeg', 'webp'))
|
166 |
+
|
167 |
+
|
168 |
+
def is_image(image_path: str) -> bool:
|
169 |
+
if image_path and os.path.isfile(image_path):
|
170 |
+
mimetype, _ = mimetypes.guess_type(image_path)
|
171 |
+
return bool(mimetype and mimetype.startswith('image/'))
|
172 |
+
return False
|
173 |
+
|
174 |
+
|
175 |
+
def is_video(video_path: str) -> bool:
|
176 |
+
if video_path and os.path.isfile(video_path):
|
177 |
+
mimetype, _ = mimetypes.guess_type(video_path)
|
178 |
+
return bool(mimetype and mimetype.startswith('video/'))
|
179 |
+
return False
|
180 |
+
|
181 |
+
|
182 |
+
def conditional_download(download_directory_path: str, urls: List[str]) -> None:
|
183 |
+
if not os.path.exists(download_directory_path):
|
184 |
+
os.makedirs(download_directory_path)
|
185 |
+
for url in urls:
|
186 |
+
download_file_path = os.path.join(download_directory_path, os.path.basename(url))
|
187 |
+
if not os.path.exists(download_file_path):
|
188 |
+
request = urllib.request.urlopen(url) # type: ignore[attr-defined]
|
189 |
+
total = int(request.headers.get('Content-Length', 0))
|
190 |
+
with tqdm(total=total, desc='Downloading', unit='B', unit_scale=True, unit_divisor=1024) as progress:
|
191 |
+
urllib.request.urlretrieve(url, download_file_path, reporthook=lambda count, block_size, total_size: progress.update(block_size)) # type: ignore[attr-defined]
|
192 |
+
|
193 |
+
|
194 |
+
def resolve_relative_path(path: str) -> str:
|
195 |
+
return os.path.abspath(os.path.join(os.path.dirname(__file__), path))
|
|
|
|
|
|
|
|
sulkuPypi.py
CHANGED
@@ -1,130 +1,113 @@
|
|
1 |
-
import requests
|
2 |
-
import time
|
3 |
-
import nycklar.nodes as nodes
|
4 |
-
from cryptography.fernet import Fernet
|
5 |
-
|
6 |
-
#Sulkupypi será el que en un futuro se volverá un paquete de python que instalarás y en el futuro quizá comercializarás.
|
7 |
-
|
8 |
-
base_url = "https://moibe-sulku-fastapi-docker.hf.space/"
|
9 |
-
userfile = "gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkABSI6FJrdZDQKk_5lpJOgJoMChxlniw=="
|
10 |
-
#Ojo, cuando el userfile termina con símbolo igual y supongo que también si empieza, causa problemas, la solución, ...
|
11 |
-
#... implementar más adelante desde ser agregar un caractér delimitador y despúes quitarlo, esto para evitar problemas...
|
12 |
-
#... con el símbolo =, ? y &. Dicho problema solo sucede cuando lo recibe como query params no como path params.
|
13 |
-
work = "picswap"
|
14 |
-
|
15 |
-
#Todas son llamadas a la API, excepto encrypta, que es una herramienta para prepara precisamente, ...
|
16 |
-
#lo que le vas a enviar a la API.
|
17 |
-
def encripta(username):
|
18 |
-
|
19 |
-
key = nodes.key
|
20 |
-
fernet = Fernet(key)
|
21 |
-
|
22 |
-
string_original = username
|
23 |
-
string_encriptado = fernet.encrypt(string_original.encode("utf-8"))
|
24 |
-
string_desencriptado = fernet.decrypt(string_encriptado).decode("utf-8")
|
25 |
-
|
26 |
-
print("String original:", string_original)
|
27 |
-
print("String encriptado:", string_encriptado)
|
28 |
-
print("String desencriptado:", string_desencriptado)
|
29 |
-
|
30 |
-
return string_encriptado
|
31 |
-
|
32 |
-
def getData():
|
33 |
-
|
34 |
-
method = "getData/"
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
response
|
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 |
-
response = requests.get(api_url)
|
115 |
-
|
116 |
-
if response.status_code == 200:
|
117 |
-
print("Conexión a Sulku successful...")
|
118 |
-
tokens = response.json()
|
119 |
-
print("Tokens:", tokens)
|
120 |
-
else:
|
121 |
-
print("Error al obtener el elemento todo:", response.status_code)
|
122 |
-
|
123 |
-
return tokens
|
124 |
-
|
125 |
-
if __name__ == "__main__":
|
126 |
-
getTokens(userfile)
|
127 |
-
authorize(18,'picswap')
|
128 |
-
debitTokens(userfile, work)
|
129 |
-
#debitTokensQ(userfile, work)
|
130 |
-
#pass
|
|
|
1 |
+
import requests
|
2 |
+
import time
|
3 |
+
import nycklar.nodes as nodes
|
4 |
+
from cryptography.fernet import Fernet
|
5 |
+
|
6 |
+
#Sulkupypi será el que en un futuro se volverá un paquete de python que instalarás y en el futuro quizá comercializarás.
|
7 |
+
|
8 |
+
base_url = "https://moibe-sulku-fastapi-docker.hf.space/"
|
9 |
+
userfile = "gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkABSI6FJrdZDQKk_5lpJOgJoMChxlniw=="
|
10 |
+
#Ojo, cuando el userfile termina con símbolo igual y supongo que también si empieza, causa problemas, la solución, ...
|
11 |
+
#... implementar más adelante desde ser agregar un caractér delimitador y despúes quitarlo, esto para evitar problemas...
|
12 |
+
#... con el símbolo =, ? y &. Dicho problema solo sucede cuando lo recibe como query params no como path params.
|
13 |
+
work = "picswap"
|
14 |
+
|
15 |
+
#Todas son llamadas a la API, excepto encrypta, que es una herramienta para prepara precisamente, ...
|
16 |
+
#lo que le vas a enviar a la API.
|
17 |
+
def encripta(username):
|
18 |
+
|
19 |
+
key = nodes.key
|
20 |
+
fernet = Fernet(key)
|
21 |
+
|
22 |
+
string_original = username
|
23 |
+
string_encriptado = fernet.encrypt(string_original.encode("utf-8"))
|
24 |
+
string_desencriptado = fernet.decrypt(string_encriptado).decode("utf-8")
|
25 |
+
|
26 |
+
print("String original:", string_original)
|
27 |
+
print("String encriptado:", string_encriptado)
|
28 |
+
print("String desencriptado:", string_desencriptado)
|
29 |
+
|
30 |
+
return string_encriptado
|
31 |
+
|
32 |
+
def getData():
|
33 |
+
|
34 |
+
method = "getData/"
|
35 |
+
api_url = base_url + method
|
36 |
+
response = requests.get(api_url)
|
37 |
+
|
38 |
+
if response.status_code == 200:
|
39 |
+
print("Conexión a Sulku successful...")
|
40 |
+
data = response.json()
|
41 |
+
#IMPORTANTE: Aquí se obtuvo la lista completa de accesos.
|
42 |
+
#Future, se puede optimizar eso en cuanto a seguridad?
|
43 |
+
else:
|
44 |
+
print("Error al obtener el elemento todo:", response.status_code)
|
45 |
+
|
46 |
+
return data
|
47 |
+
|
48 |
+
def getTokens(userfile):
|
49 |
+
|
50 |
+
method = "getTokens/"
|
51 |
+
api_url = base_url + method + userfile
|
52 |
+
response = requests.get(api_url)
|
53 |
+
|
54 |
+
if response.status_code == 200:
|
55 |
+
print("Conexión a Sulku successful...")
|
56 |
+
tokens = response.json()
|
57 |
+
print("Tokens:", tokens)
|
58 |
+
else:
|
59 |
+
print("Error al obtener el elemento todo:", response.status_code)
|
60 |
+
|
61 |
+
return tokens
|
62 |
+
|
63 |
+
def authorize(tokens, work):
|
64 |
+
|
65 |
+
method = "authorize/"
|
66 |
+
api_url = base_url + method + str(tokens) + "/" + work
|
67 |
+
response = requests.get(api_url)
|
68 |
+
|
69 |
+
if response.status_code == 200:
|
70 |
+
print("Conexión a Sulku successful...")
|
71 |
+
autorizacion = response.json()
|
72 |
+
print("Autorización:", autorizacion)
|
73 |
+
else:
|
74 |
+
print("Error al obtener el elemento todo:", response.status_code)
|
75 |
+
|
76 |
+
return autorizacion
|
77 |
+
|
78 |
+
def debitTokens(userfile, work):
|
79 |
+
|
80 |
+
method = "debitTokens/"
|
81 |
+
api_url = base_url + method + userfile + "/" + work
|
82 |
+
response = requests.get(api_url)
|
83 |
+
|
84 |
+
if response.status_code == 200:
|
85 |
+
print("Conexión a Sulku successful...")
|
86 |
+
tokens = response.json()
|
87 |
+
print("Tokens:", tokens)
|
88 |
+
else:
|
89 |
+
print("Error al obtener el elemento todo:", response.status_code)
|
90 |
+
|
91 |
+
return tokens
|
92 |
+
|
93 |
+
def debitTokensQ(userfile, work):
|
94 |
+
|
95 |
+
#debitTokens pero con QueryParams, (los query params sirve para ocasiones en los que usas dos de un mismo query param para abtener el resultado de un AND o rangos como...
|
96 |
+
#... clima por ejemplo.)
|
97 |
+
method = "debitTokens?"
|
98 |
+
api_url = base_url + method + "userfile=" + userfile + "&" + "work=" + work
|
99 |
+
response = requests.get(api_url)
|
100 |
+
|
101 |
+
if response.status_code == 200:
|
102 |
+
print("Conexión a Sulku successful...")
|
103 |
+
tokens = response.json()
|
104 |
+
print("Tokens:", tokens)
|
105 |
+
else:
|
106 |
+
print("Error al obtener el elemento todo:", response.status_code)
|
107 |
+
|
108 |
+
return tokens
|
109 |
+
|
110 |
+
if __name__ == "__main__":
|
111 |
+
getTokens(userfile)
|
112 |
+
authorize(18,'picswap')
|
113 |
+
debitTokens(userfile, work)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tools.py
CHANGED
@@ -1,14 +1,9 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
def actualizar_creditos(nuevos_creditos, usuario):
|
4 |
|
5 |
html_credits = f"""
|
6 |
-
<div
|
|
|
|
|
7 |
"""
|
8 |
|
9 |
-
return html_credits
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
# Para actualizar los créditos a 500:
|
14 |
-
actualizar_creditos(500, "Moibe")
|
|
|
|
|
|
|
1 |
def actualizar_creditos(nuevos_creditos, usuario):
|
2 |
|
3 |
html_credits = f"""
|
4 |
+
<div>
|
5 |
+
<div style="text-align: left;">👤<b>Username: </b> {usuario}</div><div style="text-align: right;">💶<b>Credits Available: </b> {nuevos_creditos}</div>
|
6 |
+
</div>
|
7 |
"""
|
8 |
|
9 |
+
return html_credits
|
|
|
|
|
|
|
|
|
|