File size: 3,685 Bytes
ed771e1
 
 
 
 
 
1dd54ec
1aee7f2
ed771e1
 
 
 
2e4eff2
 
bc2b113
 
ed771e1
ec0be43
ed771e1
 
 
 
2e4eff2
ed771e1
 
 
8cd11d2
62282a3
ed771e1
 
 
 
 
 
8cd11d2
10619d3
ed771e1
 
2e4eff2
ed771e1
 
2e4eff2
ed771e1
 
 
48c7119
ed771e1
 
 
 
48c7119
1dd54ec
1093639
ed771e1
 
 
 
 
 
2e4eff2
ed771e1
 
 
10619d3
ed771e1
 
 
1abf920
 
 
ed771e1
 
 
 
 
 
878a922
1abf920
ed771e1
bb7a620
1abf920
ed771e1
59778a1
ed771e1
 
 
 
 
 
 
 
 
5236afa
ed771e1
1abf920
 
 
ed771e1
 
 
 
 
 
 
0239c97
1093639
24b09fe
1aee7f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 perform, la cantidad de tokens es: ", gr.State.tokens)
    print("Estando en perform, el usuario es: ", gr.State.usuario)
    #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-source-face" 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"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.")
        html_credits = tools.actualizar_creditos(gr.State.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 display_tokens():

    print("Ejecutando display_tokens, tienes: ", gr.State.tokens)
    display = tools.actualizar_creditos(gr.State.tokens)
    return display

#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')

#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)