Spaces:
Sleeping
Sleeping
Moibe
commited on
Commit
·
e64103c
1
Parent(s):
e8ba8d3
Perfection
Browse files- aiicon.png +0 -0
- app.py +38 -16
aiicon.png
ADDED
![]() |
app.py
CHANGED
@@ -3,36 +3,58 @@ import gradio as gr
|
|
3 |
get_local_storage = """
|
4 |
function() {
|
5 |
globalThis.setStorage = (key, value)=>{
|
6 |
-
localStorage.setItem(key,
|
7 |
}
|
8 |
globalThis.getStorage = (key, value)=>{
|
9 |
obtencion = localStorage.getItem(key)
|
10 |
console.log("Dentro de getStorage:", obtencion)
|
11 |
-
return
|
12 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
return [text_input, local_data];
|
15 |
}
|
16 |
"""
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
with gr.Blocks() as block:
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
text_input =
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
btn =
|
31 |
-
|
32 |
-
|
33 |
None,
|
34 |
inputs=None,
|
35 |
-
outputs=[
|
36 |
-
|
37 |
)
|
38 |
block.launch(debug=True)
|
|
|
3 |
get_local_storage = """
|
4 |
function() {
|
5 |
globalThis.setStorage = (key, value)=>{
|
6 |
+
localStorage.setItem(key, value)
|
7 |
}
|
8 |
globalThis.getStorage = (key, value)=>{
|
9 |
obtencion = localStorage.getItem(key)
|
10 |
console.log("Dentro de getStorage:", obtencion)
|
11 |
+
return obtencion
|
12 |
}
|
13 |
+
|
14 |
+
if (!localStorage.getItem('tokens')) {
|
15 |
+
localStorage.setItem('tokens', 5);
|
16 |
+
}
|
17 |
+
|
18 |
+
const legado = localStorage.getItem('tokens');
|
19 |
+
|
20 |
+
return legado;
|
21 |
|
|
|
22 |
}
|
23 |
"""
|
24 |
|
25 |
+
def predict(text_input, tokens_label):
|
26 |
+
|
27 |
+
tokens_texto = int(tokens_label) - 1
|
28 |
+
resultado_texto = "Hola " + text_input + ", éste es el resultado."
|
29 |
+
print("Tokens_Label:", tokens_label)
|
30 |
|
31 |
+
if tokens_texto > 0:
|
32 |
+
|
33 |
+
print("Saldo Positivo")
|
34 |
+
return tokens_texto, resultado_texto, gr.Button(interactive=True)
|
35 |
+
|
36 |
+
else:
|
37 |
+
|
38 |
+
print("Saldo negativo")
|
39 |
+
return tokens_texto, resultado_texto, gr.Button(interactive=False)
|
40 |
|
41 |
with gr.Blocks() as block:
|
42 |
+
|
43 |
+
tokens_label = gr.Text(label="Tokens Disponibles", interactive = False)
|
44 |
+
text_input = gr.Text(label="Tu Nombre:")
|
45 |
+
resultadoFinal = gr.Text(label="Resultado")
|
46 |
|
47 |
+
#text_input.change(None, tokens_label, tokens_label, js="(v)=>{ getStorage('text_input',v) }")
|
48 |
+
tokens_label.change(None, tokens_label, None, js="(v)=>{ setStorage('tokens',v) }")
|
49 |
+
|
50 |
+
#resultadoFinal.change(None, text_input, resultadoFinal, js="(v)=>{ getStorage('text_input') }")
|
51 |
+
btn = gr.Button("Enviar", icon="aiicon.png", interactive = True)
|
52 |
+
btn.click(fn=predict, inputs=[text_input, tokens_label], outputs=[tokens_label, resultadoFinal, btn])
|
53 |
+
|
54 |
+
block.load(
|
55 |
None,
|
56 |
inputs=None,
|
57 |
+
outputs=[tokens_label],
|
58 |
+
js=get_local_storage,
|
59 |
)
|
60 |
block.launch(debug=True)
|