skytnt commited on
Commit
2b4fe99
β€’
1 Parent(s): 93e3f47

fix symbol input

Browse files
Files changed (1) hide show
  1. app.py +3 -21
app.py CHANGED
@@ -122,25 +122,6 @@ def create_to_symbol_fn(hps):
122
 
123
  return to_symbol_fn
124
 
125
-
126
- download_audio_js = """
127
- () =>{{
128
- let root = document.querySelector("body > gradio-app");
129
- if (root.shadowRoot != null)
130
- root = root.shadowRoot;
131
- let audio = root.querySelector("#{audio_id}").querySelector("audio");
132
- if (audio == undefined)
133
- return;
134
- audio = audio.src;
135
- let oA = document.createElement("a");
136
- oA.download = Math.floor(Math.random()*100000000)+'.wav';
137
- oA.href = audio;
138
- document.body.appendChild(oA);
139
- oA.click();
140
- oA.remove();
141
- }}
142
- """
143
-
144
  if __name__ == '__main__':
145
  parser = argparse.ArgumentParser()
146
  parser.add_argument('--device', type=str, default='cpu')
@@ -221,7 +202,7 @@ if __name__ == '__main__':
221
  symbol_list = gr.Dataset(label="Symbol list", components=[tts_input1],
222
  samples=[[x] for x in symbols],
223
  elem_id=f"symbol-list{i}")
224
- symbol_list_json = gr.Json(value=symbols, visible=False)
225
  tts_submit = gr.Button("Generate", variant="primary")
226
  tts_output1 = gr.Textbox(label="Output Message")
227
  tts_output2 = gr.Audio(label="Output Audio", elem_id=f"tts-audio{i}")
@@ -230,7 +211,7 @@ if __name__ == '__main__':
230
  symbol_input.change(to_symbol_fn,
231
  [symbol_input, tts_input1, temp_text_var],
232
  [tts_input1, temp_text_var])
233
- symbol_list.click(None, [symbol_list, symbol_list_json], [],
234
  js=f"""
235
  (i,symbols) => {{
236
  let root = document.querySelector("body > gradio-app");
@@ -240,6 +221,7 @@ if __name__ == '__main__':
240
  let startPos = text_input.selectionStart;
241
  let endPos = text_input.selectionEnd;
242
  let oldTxt = text_input.value;
 
243
  let result = oldTxt.substring(0, startPos) + symbols[i] + oldTxt.substring(endPos);
244
  text_input.value = result;
245
  let x = window.scrollX, y = window.scrollY;
 
122
 
123
  return to_symbol_fn
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  if __name__ == '__main__':
126
  parser = argparse.ArgumentParser()
127
  parser.add_argument('--device', type=str, default='cpu')
 
202
  symbol_list = gr.Dataset(label="Symbol list", components=[tts_input1],
203
  samples=[[x] for x in symbols],
204
  elem_id=f"symbol-list{i}")
205
+ symbol_list_state = gr.State(value=symbols)
206
  tts_submit = gr.Button("Generate", variant="primary")
207
  tts_output1 = gr.Textbox(label="Output Message")
208
  tts_output2 = gr.Audio(label="Output Audio", elem_id=f"tts-audio{i}")
 
211
  symbol_input.change(to_symbol_fn,
212
  [symbol_input, tts_input1, temp_text_var],
213
  [tts_input1, temp_text_var])
214
+ symbol_list.click(None, [symbol_list, symbol_list_state], [],
215
  js=f"""
216
  (i,symbols) => {{
217
  let root = document.querySelector("body > gradio-app");
 
221
  let startPos = text_input.selectionStart;
222
  let endPos = text_input.selectionEnd;
223
  let oldTxt = text_input.value;
224
+ console.log(i, symbols, symbols[i])
225
  let result = oldTxt.substring(0, startPos) + symbols[i] + oldTxt.substring(endPos);
226
  text_input.value = result;
227
  let x = window.scrollX, y = window.scrollY;