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