Spaces:
elioonpc
/
Runtime error

gorkemgoknar commited on
Commit
f38c6b2
1 Parent(s): def995e

checkbox to disable language auto-detection

Browse files

Notice: By default language detection is there to minimize errors

Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -21,7 +21,7 @@ DEVICE_ASSERT_DETECTED=0
21
  DEVICE_ASSERT_PROMPT=None
22
  DEVICE_ASSERT_LANG=None
23
 
24
- def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
25
  if agree == True:
26
  supported_languages=["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn"]
27
 
@@ -40,12 +40,12 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
40
  language_predicted = "zh-cn"
41
  print(f"Detected language:{language_predicted}, Chosen language:{language}")
42
 
43
- if len(prompt)>10:
44
  #allow any language for short text as some may be common
45
- if language_predicted != language:
46
  #Please duplicate and remove this check if you really want this
47
  #Or auto-detector fails to identify language (which it can on pretty short text or mixed text)
48
- gr.Warning(f"Auto-Predicted Language in prompt (detected: {language_predicted}) does not match language you chose (chosen: {language}) , please choose correct language id. If you think this is incorrect please duplicate this space and modify code.")
49
 
50
  return (
51
  None,
@@ -73,7 +73,7 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
73
  None,
74
  )
75
  if len(prompt)>200:
76
- gr.Warning("Text length limited to 200 characters for this demo, please try shorter text")
77
  return (
78
  None,
79
  None,
@@ -82,7 +82,7 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
82
  if DEVICE_ASSERT_DETECTED:
83
  global DEVICE_ASSERT_PROMPT
84
  global DEVICE_ASSERT_LANG
85
- #we want to know whos caused this error
86
  print(f"Unrecoverable exception caused by language:{DEVICE_ASSERT_LANG} prompt:{DEVICE_ASSERT_PROMPT}")
87
 
88
  try:
@@ -158,6 +158,7 @@ examples = [
158
  "examples/female.wav",
159
  None,
160
  False,
 
161
  True,
162
  ],
163
  [
@@ -166,6 +167,7 @@ examples = [
166
  "examples/male.wav",
167
  None,
168
  False,
 
169
  True,
170
  ],
171
  [
@@ -174,6 +176,7 @@ examples = [
174
  "examples/female.wav",
175
  None,
176
  False,
 
177
  True,
178
  ],
179
  [
@@ -182,6 +185,7 @@ examples = [
182
  "examples/male.wav",
183
  None,
184
  False,
 
185
  True,
186
  ],
187
  [
@@ -190,6 +194,7 @@ examples = [
190
  "examples/female.wav",
191
  None,
192
  False,
 
193
  True,
194
  ],
195
  [
@@ -198,6 +203,7 @@ examples = [
198
  "examples/male.wav",
199
  None,
200
  False,
 
201
  True,
202
  ],
203
  [
@@ -206,6 +212,7 @@ examples = [
206
  "examples/female.wav",
207
  None,
208
  False,
 
209
  True,
210
  ],
211
  [
@@ -214,6 +221,7 @@ examples = [
214
  "examples/female.wav",
215
  None,
216
  False,
 
217
  True,
218
  ],
219
  [
@@ -222,6 +230,7 @@ examples = [
222
  "examples/female.wav",
223
  None,
224
  False,
 
225
  True,
226
  ],
227
  [
@@ -230,6 +239,7 @@ examples = [
230
  "examples/male.wav",
231
  None,
232
  False,
 
233
  True,
234
  ],
235
  [
@@ -238,6 +248,7 @@ examples = [
238
  "examples/female.wav",
239
  None,
240
  False,
 
241
  True,
242
  ],
243
  [
@@ -246,6 +257,7 @@ examples = [
246
  "examples/female.wav",
247
  None,
248
  False,
 
249
  True,
250
  ],
251
  ]
@@ -294,6 +306,9 @@ gr.Interface(
294
  gr.Checkbox(label="Check to use Microphone as Reference",
295
  value=False,
296
  info="Notice: Microphone input may not work properly under traffic",),
 
 
 
297
  gr.Checkbox(
298
  label="Agree",
299
  value=False,
 
21
  DEVICE_ASSERT_PROMPT=None
22
  DEVICE_ASSERT_LANG=None
23
 
24
+ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic,no_lang_auto_detect, agree):
25
  if agree == True:
26
  supported_languages=["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn"]
27
 
 
40
  language_predicted = "zh-cn"
41
  print(f"Detected language:{language_predicted}, Chosen language:{language}")
42
 
43
+ if len(prompt)>15:
44
  #allow any language for short text as some may be common
45
+ if language_predicted != language and not no_lang_auto_detect:
46
  #Please duplicate and remove this check if you really want this
47
  #Or auto-detector fails to identify language (which it can on pretty short text or mixed text)
48
+ gr.Warning(f"It looks like your text isn’t the language you chose , if you’re sure the text is the same language you chose, please check disable language auto-detection checkbox" )
49
 
50
  return (
51
  None,
 
73
  None,
74
  )
75
  if len(prompt)>200:
76
+ gr.Warning("Text length limited to 200 characters for this demo, please try shorter text. You can clone this space and edit code for your own usage")
77
  return (
78
  None,
79
  None,
 
82
  if DEVICE_ASSERT_DETECTED:
83
  global DEVICE_ASSERT_PROMPT
84
  global DEVICE_ASSERT_LANG
85
+ #It will likely never come here as we restart space on first unrecoverable error now
86
  print(f"Unrecoverable exception caused by language:{DEVICE_ASSERT_LANG} prompt:{DEVICE_ASSERT_PROMPT}")
87
 
88
  try:
 
158
  "examples/female.wav",
159
  None,
160
  False,
161
+ False,
162
  True,
163
  ],
164
  [
 
167
  "examples/male.wav",
168
  None,
169
  False,
170
+ False,
171
  True,
172
  ],
173
  [
 
176
  "examples/female.wav",
177
  None,
178
  False,
179
+ False,
180
  True,
181
  ],
182
  [
 
185
  "examples/male.wav",
186
  None,
187
  False,
188
+ False,
189
  True,
190
  ],
191
  [
 
194
  "examples/female.wav",
195
  None,
196
  False,
197
+ False,
198
  True,
199
  ],
200
  [
 
203
  "examples/male.wav",
204
  None,
205
  False,
206
+ False,
207
  True,
208
  ],
209
  [
 
212
  "examples/female.wav",
213
  None,
214
  False,
215
+ False,
216
  True,
217
  ],
218
  [
 
221
  "examples/female.wav",
222
  None,
223
  False,
224
+ False,
225
  True,
226
  ],
227
  [
 
230
  "examples/female.wav",
231
  None,
232
  False,
233
+ False,
234
  True,
235
  ],
236
  [
 
239
  "examples/male.wav",
240
  None,
241
  False,
242
+ False,
243
  True,
244
  ],
245
  [
 
248
  "examples/female.wav",
249
  None,
250
  False,
251
+ False,
252
  True,
253
  ],
254
  [
 
257
  "examples/female.wav",
258
  None,
259
  False,
260
+ False,
261
  True,
262
  ],
263
  ]
 
306
  gr.Checkbox(label="Check to use Microphone as Reference",
307
  value=False,
308
  info="Notice: Microphone input may not work properly under traffic",),
309
+ gr.Checkbox(label="Do not use language auto-detect",
310
+ value=False,
311
+ info="Check to disable language detection, if your really intend to",),
312
  gr.Checkbox(
313
  label="Agree",
314
  value=False,