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|
| 4 |
+
from data import usuarios
|
| 5 |
+
import encrypter
|
| 6 |
+
import time
|
| 7 |
+
import nycklar.nodes
|
| 8 |
+
|
| 9 |
+
#Funciones
|
| 10 |
+
def authenticate(username, password):
|
| 11 |
+
|
| 12 |
+
for u, p in usuarios:
|
| 13 |
+
#Si el usuario y la contraseña son correctas...
|
| 14 |
+
if username == u and password == p:
|
| 15 |
+
#Agrego el nombre del usuario al estado general.
|
| 16 |
+
gr.State.usuario = username
|
| 17 |
+
#Bienvenida al usuario...
|
| 18 |
+
print("Welcome ", gr.State.usuario)
|
| 19 |
+
|
| 20 |
+
#Capsule es el usuario encriptado que enviarás a la API de Sulku.
|
| 21 |
+
capsule = encrypter.encripta(gr.State.usuario).decode("utf-8") #decode es para quitarle el 'b
|
| 22 |
+
gr.State.capsule = capsule
|
| 23 |
+
|
| 24 |
+
#Checa cuantos tokens tiene ese usuario via la API de Sulku:
|
| 25 |
+
gr.State.tokens = sulkuPypi.getTokens(capsule)
|
| 26 |
+
|
| 27 |
+
print(f"Tienes: {gr.State.tokens} tokens. ")
|
| 28 |
+
|
| 29 |
+
return True
|
| 30 |
+
#Si no hubo coincidencia regresas un false.
|
| 31 |
+
return False
|
| 32 |
+
|
| 33 |
+
#Función principal
|
| 34 |
+
def perform(input1, input2):
|
| 35 |
+
|
| 36 |
+
print("Estando en perform182, la cantidad de tokens es: ", gr.State.tokens)
|
| 37 |
+
#Revisaremos de nuevo:
|
| 38 |
+
gr.State.tokens = sulkuPypi.getTokens(encrypter.encripta(gr.State.usuario).decode("utf-8")) #Todo en una línea.
|
| 39 |
+
print("Ahora tienes: ", gr.State.tokens)
|
| 40 |
+
|
| 41 |
+
#Después autoriza.
|
| 42 |
+
#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.
|
| 43 |
+
autorizacion = sulkuPypi.authorize(gr.State.tokens, 'picswap')
|
| 44 |
+
print("La autorización es: ", autorizacion)
|
| 45 |
+
|
| 46 |
+
info_window = ""
|
| 47 |
+
|
| 48 |
+
#Después ejecuta la masa.
|
| 49 |
+
if autorizacion is True:
|
| 50 |
+
|
| 51 |
+
path = mass(input1,input2)
|
| 52 |
+
|
| 53 |
+
else:
|
| 54 |
+
info_window = "Out of credits..."
|
| 55 |
+
path = 'no-result.png'
|
| 56 |
+
return path, info_window, btn_buy
|
| 57 |
+
|
| 58 |
+
print(f"El path final fue {path}, si es no-result, no debites y controla la info window.")
|
| 59 |
+
print(f"El type de path es: ", type(path))
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
print("Convirtiendo path a string...")
|
| 63 |
+
path_string = str(path)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
print("Path_string = ", path_string)
|
| 67 |
+
|
| 68 |
+
if "no-result" not in path_string:
|
| 69 |
+
#Si el path NO tiene no-result, todo funcionó bien, por lo tanto debita.
|
| 70 |
+
print("Se obtuvo un resultado, debitaremos.")
|
| 71 |
+
#Y finalmente debita los tokens.
|
| 72 |
+
gr.State.tokens = sulkuPypi.debitTokens(gr.State.capsule, "picswap")
|
| 73 |
+
print(f"Y ahora tienes: {gr.State.tokens} tokens.")
|
| 74 |
+
info_window = "Image ready!"
|
| 75 |
+
|
| 76 |
+
else:
|
| 77 |
+
print("No se detectó un rostro...")
|
| 78 |
+
info_window = "No face in source path detected."
|
| 79 |
+
print(f"Y ahora tienes: {gr.State.tokens} tokens.")
|
| 80 |
+
lbl_credits = "Nuevo texto..."
|
| 81 |
+
#No se hizo un proceso, por lo tanto no debitaremos.
|
| 82 |
+
#En el futuro, como regla de negocio, podría cambiar y que si debitemos.
|
| 83 |
+
|
| 84 |
+
return path, info_window, btn_buy
|
| 85 |
+
|
| 86 |
+
def click_buy():
|
| 87 |
+
|
| 88 |
+
print("Ejecutando change...")
|
| 89 |
+
|
| 90 |
+
nuevo_markdown = """
|
| 91 |
+
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
+
return nuevo_markdown
|
| 95 |
+
|
| 96 |
+
def display_tokens():
|
| 97 |
+
|
| 98 |
+
print("Ejecutando display_tokens...")
|
| 99 |
+
|
| 100 |
+
return gr.State.tokens
|
| 101 |
+
|
| 102 |
+
#LOCAL VARIABLES
|
| 103 |
+
# gr.State.usuario = "briggsboardman"
|
| 104 |
+
# Capsule es el usuario encriptado que enviarás a la API de Sulku.
|
| 105 |
+
# capsule = encrypter.encripta(gr.State.usuario).decode("utf-8") #decode es para quitarle el 'b
|
| 106 |
+
# gr.State.capsule = capsule
|
| 107 |
+
# gr.State.tokens = 20
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
#Inputs
|
| 111 |
+
source_image = gr.Image(label="Source")
|
| 112 |
+
destination_image = gr.Image(label="Destination")
|
| 113 |
+
|
| 114 |
+
#Outputs
|
| 115 |
+
result_image = gr.Image(label="Blend Result")
|
| 116 |
+
#txt_console = gr.Textbox(label="Console", value="AI Engine Ready...", interactive=False)
|
| 117 |
+
lbl_console = gr.Label(label="AI Terminal Messages", value="AI Engine ready...", container=True)
|
| 118 |
+
btn_buy = gr.Button("Buy More", visible=True, size='lg')
|
| 119 |
+
#btn_buy.click(fn=click_buy, outputs=mrk_title)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
#Gradio themes:
|
| 123 |
+
# — gr.themes.Base()
|
| 124 |
+
# — gr.themes.Default()
|
| 125 |
+
# — gr.themes.Glass()
|
| 126 |
+
# — gr.themes.Monochrome()
|
| 127 |
+
# — gr.themes.Soft()
|
| 128 |
+
|
| 129 |
+
#valor = gr.State.tokens
|
| 130 |
+
valor = ""
|
| 131 |
+
|
| 132 |
+
with gr.Blocks(theme=gr.themes.Base(), css="footer {visibility: hidden}") as main:
|
| 133 |
+
|
| 134 |
+
with gr.Row():
|
| 135 |
+
gr.Markdown(visible=True)
|
| 136 |
+
gr.Markdown(visible=True)
|
| 137 |
+
gr.Markdown(visible=True)
|
| 138 |
+
lbl_credits = gr.Label(label="Credits Available", value=valor, scale=1)
|
| 139 |
+
result_image.change(fn=display_tokens, outputs=lbl_credits)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
with gr.Row():
|
| 144 |
+
|
| 145 |
+
demo = gr.Interface(
|
| 146 |
+
fn=perform,
|
| 147 |
+
title="",
|
| 148 |
+
inputs=[source_image, destination_image],
|
| 149 |
+
outputs=[result_image, lbl_console, btn_buy],
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
main.launch(auth=authenticate)
|