acumplid commited on
Commit
7603d55
1 Parent(s): 5688ad2

Implemented counter code and fix bug in function returning of error input

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -16,7 +16,7 @@ def submit_input(input_, repetition_penalty, temperature):
16
  outputs = generate(input_, repetition_penalty, temperature)
17
  if input_.strip() == "":
18
  gr.Warning('No és possible processar un input buit')
19
- return None
20
  if outputs is None:
21
  gr.Warning("""
22
  És possible que no hagi trobat el lloc o la data (de dijous a dilluns).
@@ -40,20 +40,28 @@ def clean():
40
  None,
41
  None,
42
  None,
43
- gr.Slider.update(value=1.0),
44
- gr.Slider.update(value=1.0),
45
  )
46
 
47
 
48
  with gr.Blocks(**AinaGradioTheme().get_kwargs()) as demo:
49
  with gr.Row():
50
  with gr.Column():
 
 
 
 
 
51
  input_ = Textbox(
52
  lines=11,
53
  label="Input",
54
  placeholder="e.g. Prompt example."
55
  )
56
- characters_counter = gr.Markdown(f"""<span id=counter> 0 / {MAX_NEW_TOKENS} </span>""")
 
 
 
57
  with gr.Row():
58
  clear_btn = Button(
59
  "Clear",
@@ -103,14 +111,21 @@ with gr.Blocks(**AinaGradioTheme().get_kwargs()) as demo:
103
  input_.change(fn=change_interactive, inputs=[input_], outputs=[clear_btn, submit_btn])
104
 
105
 
106
- input_.change(fn=None, inputs=input_, js=f"(i, m) => document.getElementById('counter').textContent = i.length + ' /' + {MAX_NEW_TOKENS}")
 
 
107
 
 
 
 
 
 
 
 
108
 
109
 
110
  clear_btn.click(fn=clean, inputs=[], outputs=[input_, output_answer, output_context, output_CCMA, repetition_penalty, temperature], queue=False)
111
  submit_btn.click(fn=submit_input, inputs=[input_, repetition_penalty, temperature], outputs=[output_answer, output_context, output_CCMA])
112
 
113
-
114
-
115
  # demo.queue(concurrency_count=1, api_open=False)
116
  demo.launch(show_api=True, share=True, debug=True, max_threads=1)
 
16
  outputs = generate(input_, repetition_penalty, temperature)
17
  if input_.strip() == "":
18
  gr.Warning('No és possible processar un input buit')
19
+ return None, None, None
20
  if outputs is None:
21
  gr.Warning("""
22
  És possible que no hagi trobat el lloc o la data (de dijous a dilluns).
 
40
  None,
41
  None,
42
  None,
43
+ gr.Slider(value=1.0),
44
+ gr.Slider(value=1.0),
45
  )
46
 
47
 
48
  with gr.Blocks(**AinaGradioTheme().get_kwargs()) as demo:
49
  with gr.Row():
50
  with gr.Column():
51
+ placeholder_max_token = Textbox(
52
+ visible=False,
53
+ interactive=False,
54
+ value= MAX_INPUT_CHARACTERS
55
+ )
56
  input_ = Textbox(
57
  lines=11,
58
  label="Input",
59
  placeholder="e.g. Prompt example."
60
  )
61
+ with gr.Row(variant="panel", equal_height=True):
62
+ gr.HTML("""<span id="countertext" style="display: flex; justify-content: start; color:#ef4444; font-weight: bold;"></span>""")
63
+ gr.HTML(f"""<span id="counter" style="display: flex; justify-content: end;"> <span id="inputlenght">0</span>&nbsp;/&nbsp;{MAX_INPUT_CHARACTERS}</span>""")
64
+
65
  with gr.Row():
66
  clear_btn = Button(
67
  "Clear",
 
111
  input_.change(fn=change_interactive, inputs=[input_], outputs=[clear_btn, submit_btn])
112
 
113
 
114
+ input_.change(
115
+ fn=None, inputs=[input_],
116
+ js=f"""(i) => document.getElementById('countertext').textContent = i.length > {MAX_INPUT_CHARACTERS} && 'Max length {MAX_INPUT_CHARACTERS} characters. ' || '' """)
117
 
118
+ input_.change(
119
+ fn=None,
120
+ inputs=[input_, placeholder_max_token],
121
+ js="""(i, m) => {
122
+ document.getElementById('inputlenght').textContent = i.length + ' '
123
+ document.getElementById('inputlenght').style.color = (i.length > m) ? "#ef4444" : "";
124
+ }""")
125
 
126
 
127
  clear_btn.click(fn=clean, inputs=[], outputs=[input_, output_answer, output_context, output_CCMA, repetition_penalty, temperature], queue=False)
128
  submit_btn.click(fn=submit_input, inputs=[input_, repetition_penalty, temperature], outputs=[output_answer, output_context, output_CCMA])
129
 
 
 
130
  # demo.queue(concurrency_count=1, api_open=False)
131
  demo.launch(show_api=True, share=True, debug=True, max_threads=1)