alan commited on
Commit
fe1f10a
·
1 Parent(s): f2e0348

error handling

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -277,6 +277,8 @@ DESCR = """
277
  Vote to help the community find the best available text-to-speech model!
278
 
279
  _This arena is inspired and built on [TTS Arena](https://huggingface.co/spaces/TTS-AGI/TTS-Arena)._
 
 
280
  """.strip()
281
  # INSTR = """
282
  # ## Instructions
@@ -698,12 +700,12 @@ def doresample(path_to_wav):
698
  # 2x speedup (hopefully) #
699
  ##########################
700
 
701
- def synthandreturn(text):
702
  text = text.strip()
703
  if len(text) > MAX_SAMPLE_TXT_LENGTH:
704
  raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
705
- if len(text) < MIN_SAMPLE_TXT_LENGTH:
706
- raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
707
  # if (
708
  # # test toxicity if not prepared text
709
  # text not in sents
@@ -779,7 +781,7 @@ def synthandreturn(text):
779
  raise NotImplementedError
780
 
781
  except:
782
- raise gr.Error(f'Unable to call {model} API, please try again :)')
783
  print('Done with', model)
784
  if model in {"moe-vits"}:
785
  result = result[1]
@@ -828,6 +830,12 @@ def synthandreturn(text):
828
  thread1.join()
829
  thread2.join()
830
  #debug
 
 
 
 
 
 
831
  print(results)
832
  print(list(results.keys())[0])
833
  y, sr = librosa.load(results[list(results.keys())[0]], sr=None)
@@ -995,4 +1003,4 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}
995
  gr.Markdown(f"If you use this data in your publication, please cite us!\n\nCopy the BibTeX citation to cite this source:\n\n```bibtext\n{CITATION_TEXT}\n```\n\nPlease remember that all generated audio clips should be assumed unsuitable for redistribution or commercial use.")
996
 
997
  # demo.launch()
998
- demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)
 
277
  Vote to help the community find the best available text-to-speech model!
278
 
279
  _This arena is inspired and built on [TTS Arena](https://huggingface.co/spaces/TTS-AGI/TTS-Arena)._
280
+
281
+ _We are actively maintaining this project. Suggestions via contact/discussion are welcome!_
282
  """.strip()
283
  # INSTR = """
284
  # ## Instructions
 
700
  # 2x speedup (hopefully) #
701
  ##########################
702
 
703
+ def synthandreturn(text, retry=0):
704
  text = text.strip()
705
  if len(text) > MAX_SAMPLE_TXT_LENGTH:
706
  raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
707
+ # if len(text) < MIN_SAMPLE_TXT_LENGTH:
708
+ # raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
709
  # if (
710
  # # test toxicity if not prepared text
711
  # text not in sents
 
781
  raise NotImplementedError
782
 
783
  except:
784
+ raise gr.Error(f'Unable to call {model_names[model]} API, please try again :)')
785
  print('Done with', model)
786
  if model in {"moe-vits"}:
787
  result = result[1]
 
830
  thread1.join()
831
  thread2.join()
832
  #debug
833
+ if len(results) < 2 and retry < 2:
834
+ if mdl1k not in results:
835
+ gr.Warning(f"{model_names[mdl1k]} API failed, re-sampling...")
836
+ else:
837
+ gr.Warning(f"{model_names[mdl2k]} API failed, re-sampling...")
838
+ return synthandreturn(text, retry=retry+1)
839
  print(results)
840
  print(list(results.keys())[0])
841
  y, sr = librosa.load(results[list(results.keys())[0]], sr=None)
 
1003
  gr.Markdown(f"If you use this data in your publication, please cite us!\n\nCopy the BibTeX citation to cite this source:\n\n```bibtext\n{CITATION_TEXT}\n```\n\nPlease remember that all generated audio clips should be assumed unsuitable for redistribution or commercial use.")
1004
 
1005
  # demo.launch()
1006
+ demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False, show_error=True)