Spaces:
Build error
Build error
Fix markdown
Browse files
app.py
CHANGED
|
@@ -1,136 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import sulkuPypi
|
| 3 |
-
from funciones import mass
|
| 4 |
-
from data import usuarios
|
| 5 |
-
import encrypter
|
| 6 |
-
import time
|
| 7 |
-
import nycklar.nodes
|
| 8 |
-
|
| 9 |
-
#Funciones adicionales
|
| 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 = "Welcome Usuario"
|
| 47 |
-
|
| 48 |
-
#Después ejecuta la masa.
|
| 49 |
-
if autorizacion is True:
|
| 50 |
-
|
| 51 |
-
path = mass(input1,input2)
|
| 52 |
-
|
| 53 |
-
else:
|
| 54 |
-
print("No tienes suficientes tokens...")
|
| 55 |
-
info_window = "Out of tokens..."
|
| 56 |
-
path = 'no-result.png'
|
| 57 |
-
return "Desde funcion", path, info_window, btn_buy
|
| 58 |
-
|
| 59 |
-
print(f"El path final fue {path}, si es no-result, no debites y controla la info window.")
|
| 60 |
-
print(f"El type de path es: ", type(path))
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
print("Convirtiendo path a string...")
|
| 64 |
-
path_string = str(path)
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
print("Path_string = ", path_string)
|
| 68 |
-
|
| 69 |
-
if "no-result" not in path_string:
|
| 70 |
-
#Si el path NO tiene no-result, todo funcionó bien, por lo tanto debita.
|
| 71 |
-
print("Se obtuvo un resultado, debitaremos.")
|
| 72 |
-
#Y finalmente debita los tokens.
|
| 73 |
-
gr.State.tokens = sulkuPypi.debitTokens(gr.State.capsule, "picswap")
|
| 74 |
-
print(f"Y ahora tienes: {gr.State.tokens} tokens.")
|
| 75 |
-
info_window = "Image ready!"
|
| 76 |
-
|
| 77 |
-
else:
|
| 78 |
-
print("No se detectó un rostro...")
|
| 79 |
-
info_window = "No face in source path detected."
|
| 80 |
-
print(f"Y ahora tienes: {gr.State.tokens} tokens.")
|
| 81 |
-
lbl_credits = "Nuevo texto..."
|
| 82 |
-
#No se hizo un proceso, por lo tanto no debitaremos.
|
| 83 |
-
#En el futuro, como regla de negocio, podría cambiar y que si debitemos.
|
| 84 |
-
|
| 85 |
-
return "Desde funcion", path, info_window, btn_buy
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
# print("Estoy en las declaraciones...")
|
| 89 |
-
# gr.State.usuario = "briggsboardman"
|
| 90 |
-
# #Capsule es el usuario encriptado que enviarás a la API de Sulku.
|
| 91 |
-
# capsule = encrypter.encripta(gr.State.usuario).decode("utf-8") #decode es para quitarle el 'b
|
| 92 |
-
# gr.State.capsule = capsule
|
| 93 |
-
# gr.State.tokens = 20
|
| 94 |
-
lbl_msg = gr.Label("AI Engine ready...")
|
| 95 |
-
btn_buy = gr.Button("Buy More", visible=True, size='lg')
|
| 96 |
-
result_image = gr.Image()
|
| 97 |
-
textbox = gr.Textbox("Nuevo textbox", interactive=False)
|
| 98 |
-
|
| 99 |
-
def cambio():
|
| 100 |
-
|
| 101 |
-
print("Ejecutando change...")
|
| 102 |
-
|
| 103 |
-
nuevo_markdown = """
|
| 104 |
-
# Hello World! {variable}
|
| 105 |
-
Start typing below to see the output.
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
return nuevo_markdown
|
| 109 |
-
|
| 110 |
-
with gr.Blocks(css="footer {visibility: hidden}") as main:
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
with gr.Row():
|
| 114 |
-
|
| 115 |
-
lbl_credits = gr.Label()
|
| 116 |
-
nueva_label = gr.Label("Credits")
|
| 117 |
-
mrk_title = gr.Markdown(
|
| 118 |
-
"""
|
| 119 |
-
# Hello World! {variable}
|
| 120 |
-
Start typing below to see the output.
|
| 121 |
-
""")
|
| 122 |
-
|
| 123 |
-
#lbl_msg.change(fn=cambio, lbl_msg)
|
| 124 |
-
btn_buy.click(fn=cambio, outputs=mrk_title)
|
| 125 |
-
|
| 126 |
-
with gr.Row():
|
| 127 |
-
|
| 128 |
-
demo = gr.Interface(
|
| 129 |
-
fn=perform,
|
| 130 |
-
title="",
|
| 131 |
-
inputs=[gr.Image(), gr.Image()],
|
| 132 |
-
outputs=[textbox, result_image,lbl_msg, btn_buy],
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
main.launch(auth=authenticate)
|
| 136 |
-
#demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|