Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,92 +1,92 @@
|
|
| 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'
|
| 24 |
-
return path, info_window, html_credits, btn_buy
|
| 25 |
-
|
| 26 |
-
print(f"El path final fue {path}, si es no-result, no debites y controla la info window.")
|
| 27 |
-
print(f"El type de path es: ", type(path))
|
| 28 |
-
|
| 29 |
-
print("Convirtiendo path a string...")
|
| 30 |
-
path_string = str(path)
|
| 31 |
-
|
| 32 |
-
print("Path_string = ", path_string)
|
| 33 |
-
|
| 34 |
-
if "no-source-face" not in path_string:
|
| 35 |
-
#Si el path NO tiene no-result, todo funcionó bien, por lo tanto debita.
|
| 36 |
-
print("Se obtuvo un resultado, debitaremos.")
|
| 37 |
-
#Y finalmente debita los tokens.
|
| 38 |
-
#IMPORTANTE: Tienes que reconstruir capsule ahora que ya se obtiene del request, sino, capsule sera un State para el uso...
|
| 39 |
-
#...de todos y es ahí donde radica el problema:
|
| 40 |
-
capsule = sulkuPypi.encripta(request.username).decode("utf-8") #decode es para quitarle el 'b
|
| 41 |
-
tokens = sulkuPypi.debitTokens(capsule, "picswap")
|
| 42 |
-
html_credits = tools.actualizar_creditos(tokens, request.username)
|
| 43 |
-
print(f"html credits quedó como : {html_credits} y es del tipo: {type(html_credits)}")
|
| 44 |
-
info_window = "Image ready!"
|
| 45 |
-
|
| 46 |
-
else:
|
| 47 |
-
print("No se detectó un rostro...")
|
| 48 |
-
info_window = "No face in source path detected."
|
| 49 |
-
html_credits = tools.actualizar_creditos(tokens, request.username)
|
| 50 |
-
#No se hizo un proceso, por lo tanto no debitaremos.
|
| 51 |
-
#En el futuro, como regla de negocio, podría cambiar y que si debitemos.
|
| 52 |
-
|
| 53 |
-
return path, info_window, html_credits, btn_buy
|
| 54 |
-
|
| 55 |
-
def display_tokens(request: gr.Request):
|
| 56 |
-
|
| 57 |
-
#Para desplegar o no desplegar, necesitamos saber si el usuario es new user.
|
| 58 |
-
flag = sulkuPypi.getFlag(sulkuPypi.encripta(request.username).decode("utf-8"))
|
| 59 |
-
print("La flag obtenida es: ", flag)
|
| 60 |
-
#FUTURE quizá das doble vuelta decodificando porque haya lo vuelves a encodear, prueba enviando sin decode...
|
| 61 |
-
#...llegaría codificado a encripta y prueba allá no encode.
|
| 62 |
-
tokens = sulkuPypi.getTokens(sulkuPypi.encripta(request.username).decode("utf-8"))
|
| 63 |
-
display = tools.actualizar_creditos(tokens, request.username)
|
| 64 |
-
|
| 65 |
-
return display
|
| 66 |
-
|
| 67 |
-
#Inputs
|
| 68 |
-
source_image = gr.Image(label="Source")
|
| 69 |
-
destination_image = gr.Image(label="Destination")
|
| 70 |
-
|
| 71 |
-
#Outputs
|
| 72 |
-
creditos = None
|
| 73 |
-
result_image = gr.Image(label="Blend Result")
|
| 74 |
-
txt_credits = gr.Textbox(label="Credits Available", value="", interactive=False)
|
| 75 |
-
html_credits = gr.HTML()
|
| 76 |
-
lbl_console = gr.Label(label="AI Terminal Messages", value="AI Engine ready...", container=True)
|
| 77 |
-
btn_buy = gr.Button("Buy More", visible=False, size='lg')
|
| 78 |
-
|
| 79 |
-
with gr.Blocks(theme=gr.themes.Base()
|
| 80 |
-
|
| 81 |
-
#Cargado en Load, Función, input, output
|
| 82 |
-
main.load(display_tokens, None, html_credits)
|
| 83 |
-
|
| 84 |
-
with gr.Row():
|
| 85 |
-
demo = gr.Interface(
|
| 86 |
-
fn=perform,
|
| 87 |
-
inputs=[source_image, destination_image],
|
| 88 |
-
outputs=[result_image, lbl_console, html_credits, btn_buy],
|
| 89 |
-
allow_flagging='never'
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
main.launch(auth=auth.authenticate)
|
|
|
|
| 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'
|
| 24 |
+
return path, info_window, html_credits, btn_buy
|
| 25 |
+
|
| 26 |
+
print(f"El path final fue {path}, si es no-result, no debites y controla la info window.")
|
| 27 |
+
print(f"El type de path es: ", type(path))
|
| 28 |
+
|
| 29 |
+
print("Convirtiendo path a string...")
|
| 30 |
+
path_string = str(path)
|
| 31 |
+
|
| 32 |
+
print("Path_string = ", path_string)
|
| 33 |
+
|
| 34 |
+
if "no-source-face" not in path_string:
|
| 35 |
+
#Si el path NO tiene no-result, todo funcionó bien, por lo tanto debita.
|
| 36 |
+
print("Se obtuvo un resultado, debitaremos.")
|
| 37 |
+
#Y finalmente debita los tokens.
|
| 38 |
+
#IMPORTANTE: Tienes que reconstruir capsule ahora que ya se obtiene del request, sino, capsule sera un State para el uso...
|
| 39 |
+
#...de todos y es ahí donde radica el problema:
|
| 40 |
+
capsule = sulkuPypi.encripta(request.username).decode("utf-8") #decode es para quitarle el 'b
|
| 41 |
+
tokens = sulkuPypi.debitTokens(capsule, "picswap")
|
| 42 |
+
html_credits = tools.actualizar_creditos(tokens, request.username)
|
| 43 |
+
print(f"html credits quedó como : {html_credits} y es del tipo: {type(html_credits)}")
|
| 44 |
+
info_window = "Image ready!"
|
| 45 |
+
|
| 46 |
+
else:
|
| 47 |
+
print("No se detectó un rostro...")
|
| 48 |
+
info_window = "No face in source path detected."
|
| 49 |
+
html_credits = tools.actualizar_creditos(tokens, request.username)
|
| 50 |
+
#No se hizo un proceso, por lo tanto no debitaremos.
|
| 51 |
+
#En el futuro, como regla de negocio, podría cambiar y que si debitemos.
|
| 52 |
+
|
| 53 |
+
return path, info_window, html_credits, btn_buy
|
| 54 |
+
|
| 55 |
+
def display_tokens(request: gr.Request):
|
| 56 |
+
|
| 57 |
+
#Para desplegar o no desplegar, necesitamos saber si el usuario es new user.
|
| 58 |
+
flag = sulkuPypi.getFlag(sulkuPypi.encripta(request.username).decode("utf-8"))
|
| 59 |
+
print("La flag obtenida es: ", flag)
|
| 60 |
+
#FUTURE quizá das doble vuelta decodificando porque haya lo vuelves a encodear, prueba enviando sin decode...
|
| 61 |
+
#...llegaría codificado a encripta y prueba allá no encode.
|
| 62 |
+
tokens = sulkuPypi.getTokens(sulkuPypi.encripta(request.username).decode("utf-8"))
|
| 63 |
+
display = tools.actualizar_creditos(tokens, request.username)
|
| 64 |
+
|
| 65 |
+
return display
|
| 66 |
+
|
| 67 |
+
#Inputs
|
| 68 |
+
source_image = gr.Image(label="Source")
|
| 69 |
+
destination_image = gr.Image(label="Destination")
|
| 70 |
+
|
| 71 |
+
#Outputs
|
| 72 |
+
creditos = None
|
| 73 |
+
result_image = gr.Image(label="Blend Result")
|
| 74 |
+
txt_credits = gr.Textbox(label="Credits Available", value="", interactive=False)
|
| 75 |
+
html_credits = gr.HTML()
|
| 76 |
+
lbl_console = gr.Label(label="AI Terminal Messages", value="AI Engine ready...", container=True)
|
| 77 |
+
btn_buy = gr.Button("Buy More", visible=False, size='lg')
|
| 78 |
+
|
| 79 |
+
with gr.Blocks(theme=gr.themes.Base()) as main:
|
| 80 |
+
|
| 81 |
+
#Cargado en Load, Función, input, output
|
| 82 |
+
main.load(display_tokens, None, html_credits)
|
| 83 |
+
|
| 84 |
+
with gr.Row():
|
| 85 |
+
demo = gr.Interface(
|
| 86 |
+
fn=perform,
|
| 87 |
+
inputs=[source_image, destination_image],
|
| 88 |
+
outputs=[result_image, lbl_console, html_credits, btn_buy],
|
| 89 |
+
allow_flagging='never'
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
main.launch(auth=auth.authenticate)
|