Moibe commited on
Commit
6df8572
·
1 Parent(s): 7278e4e

Back to normal

Browse files
Files changed (1) hide show
  1. app.py +141 -0
app.py CHANGED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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', variant='secondary')
96
+ result_image = gr.Image()
97
+ textbox = gr.Textbox("Nuevo textbox", interactive=False)
98
+ texto_del_markdown = """
99
+ # Hello World! {variable}
100
+ Start typing below to see the output.
101
+ """
102
+
103
+ def cambio():
104
+
105
+ print("Ejecutando change...")
106
+
107
+ nuevo_markdown = """
108
+
109
+ """
110
+
111
+ return nuevo_markdown
112
+
113
+ #Gradio themes:
114
+ # — gr.themes.Base()
115
+ # — gr.themes.Default()
116
+ # — gr.themes.Glass()
117
+ # — gr.themes.Monochrome()
118
+ # — gr.themes.Soft()
119
+
120
+ with gr.Blocks(css="footer {visibility: hidden}", theme=gr.themes.Default()) as main:
121
+
122
+ with gr.Row():
123
+
124
+ mrk_title = gr.Markdown(texto_del_markdown)
125
+ nueva_label = gr.Label("Credits")
126
+
127
+
128
+ #lbl_msg.change(fn=cambio, lbl_msg)
129
+ btn_buy.click(fn=cambio, outputs=mrk_title)
130
+
131
+ with gr.Row():
132
+
133
+ demo = gr.Interface(
134
+ fn=perform,
135
+ title="",
136
+ inputs=[gr.Image(), gr.Image()],
137
+ outputs=[textbox, result_image,lbl_msg, btn_buy],
138
+ )
139
+
140
+ main.launch(auth=authenticate)
141
+ #demo.launch()