Moibe commited on
Commit
e64103c
·
1 Parent(s): e8ba8d3

Perfection

Browse files
Files changed (2) hide show
  1. aiicon.png +0 -0
  2. 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, JSON.stringify(value))
7
  }
8
  globalThis.getStorage = (key, value)=>{
9
  obtencion = localStorage.getItem(key)
10
  console.log("Dentro de getStorage:", obtencion)
11
- return localStorage.getItem(key)
12
  }
 
 
 
 
 
 
 
 
13
 
14
- return [text_input, local_data];
15
  }
16
  """
17
 
 
 
 
 
 
18
 
19
- def predict(text_input):
20
- return "Hola mundo, éste es el resultado."
 
 
 
 
 
 
 
21
 
22
  with gr.Blocks() as block:
23
- tokens_label = gr.Label("Etiqueta")
 
 
 
24
 
25
- text_input = gr.Text(label="Input183")
26
- resultadoFinal = gr.Text(label="ResulAquí")
27
-
28
- text_input.change(None, text_input, None, _js="(v)=>{ getStorage('text_input') }")
29
- # resultadoFinal.change(None, local_data, None, _js="(v)=>{ setStorage('local_data',v) }")
30
- btn = gr.Button("Enviar")
31
- btn.click(fn=predict, inputs=[text_input], outputs=[resultadoFinal])
32
- valores = block.load(
33
  None,
34
  inputs=None,
35
- outputs=[text_input, local_data],
36
- _js=get_local_storage,
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)