Spaces:
Runtime error
Runtime error
import gradio as gr | |
import sulkuPypi | |
from funciones import mass | |
from data import usuarios | |
import time | |
import nycklar.nodes | |
import tools | |
import auth | |
#Funciones | |
#Función principal | |
def perform(input1, input2): | |
print("Estando en perform182, la cantidad de tokens es: ", gr.State.tokens) | |
#Revisaremos de nuevo: | |
gr.State.tokens = sulkuPypi.getTokens(sulkuPypi.encripta(gr.State.usuario).decode("utf-8")) #Todo en una línea. | |
print("Ahora tienes: ", gr.State.tokens) | |
#Después autoriza. | |
#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. | |
autorizacion = sulkuPypi.authorize(gr.State.tokens, 'picswap') | |
print("La autorización es: ", autorizacion) | |
#info_window = "" | |
if autorizacion is True: | |
path = mass(input1,input2) | |
else: | |
info_window = "Out of credits..." | |
path = 'no-credits.png' | |
return path, info_window, html_credits, btn_buy | |
print(f"El path final fue {path}, si es no-result, no debites y controla la info window.") | |
print(f"El type de path es: ", type(path)) | |
print("Convirtiendo path a string...") | |
path_string = str(path) | |
print("Path_string = ", path_string) | |
if "no-result" not in path_string: | |
#Si el path NO tiene no-result, todo funcionó bien, por lo tanto debita. | |
print("Se obtuvo un resultado, debitaremos.") | |
#Y finalmente debita los tokens. | |
gr.State.tokens = sulkuPypi.debitTokens(gr.State.capsule, "picswap") | |
print(f"182 Y ahora tienes: {gr.State.tokens} tokens.") | |
html_credits = tools.actualizar_creditos(gr.State.tokens) | |
print(f"html credits quedó como : {html_credits} y es del tipo: {type(html_credits)}") | |
info_window = "Image ready!" | |
else: | |
print("No se detectó un rostro...") | |
info_window = "No face in source path detected." | |
print(f"Y ahora tienes: {gr.State.tokens} tokens.") | |
#No se hizo un proceso, por lo tanto no debitaremos. | |
#En el futuro, como regla de negocio, podría cambiar y que si debitemos. | |
return path, info_window, html_credits, btn_buy | |
def click_buy(): | |
print("Ejecutando change...") | |
nuevo_markdown = """ | |
""" | |
return nuevo_markdown | |
def display_tokens(): | |
print("Ejecutando display_tokens, tienes: ", gr.State.tokens) | |
display = tools.actualizar_creditos(gr.State.tokens) | |
return display | |
#LOCAL VARIABLES | |
# gr.State.usuario = "briggsboardman" | |
# Capsule es el usuario encriptado que enviarás a la API de Sulku. | |
# capsule = encrypter.encripta(gr.State.usuario).decode("utf-8") #decode es para quitarle el 'b | |
# gr.State.capsule = capsule | |
# gr.State.tokens = 20 | |
#Inputs | |
source_image = gr.Image(label="Source") | |
destination_image = gr.Image(label="Destination") | |
#Outputs | |
print("En éste momento estoy creando los outputs...") | |
creditos = None | |
result_image = gr.Image(label="Blend Result") | |
txt_credits = gr.Textbox(label="Credits Available", value="", interactive=False) | |
html_credits = gr.HTML() | |
lbl_console = gr.Label(label="AI Terminal Messages", value="AI Engine ready...", container=True) | |
btn_buy = gr.Button("Buy More", visible=False, size='lg') | |
#btn_buy.click(fn=click_buy, outputs=mrk_title) | |
#Gradio themes: | |
# — gr.themes.Base() | |
# — gr.themes.Default() | |
# — gr.themes.Glass() | |
# — gr.themes.Monochrome() | |
# — gr.themes.Soft() | |
#valor = gr.State.tokens | |
valor = "" | |
with gr.Blocks(theme=gr.themes.Base(), css="footer {visibility: hidden}") as main: | |
#Función, input, output | |
main.load(display_tokens, None, html_credits ) | |
with gr.Row(): | |
demo = gr.Interface( | |
fn=perform, | |
title="", | |
inputs=[source_image, destination_image], | |
outputs=[result_image, lbl_console, html_credits, btn_buy], | |
allow_flagging='never' | |
) | |
main.launch(auth=auth.authenticate) |