yaya-sy commited on
Commit
f212225
Β·
verified Β·
1 Parent(s): 99e68c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -8,34 +8,23 @@ import spaces
8
  import cv2
9
  import numpy as np
10
  from PIL import Image
11
- import tempfile
12
 
13
- from parler_tts import ParlerTTSForConditionalGeneration
14
- from transformers import AutoTokenizer
15
- import soundfile as sf
16
 
17
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
18
-
19
- tts_model = ParlerTTSForConditionalGeneration.from_pretrained("CONCREE/Adia_TTS").to(device)
20
- tts_tokenizer = AutoTokenizer.from_pretrained("CONCREE/Adia_TTS")
21
-
22
- @spaces.GPU
23
  def tts(text):
24
- output_wav_path = tempfile.mktemp(suffix=".wav")
25
- # Description du style vocal
26
- description = "A clear and educational voice, with a flow adapted to learning"
27
-
28
- # GΓ©nΓ©ration
29
- input_ids = tts_tokenizer(description, return_tensors="pt").input_ids.to(device)
30
- prompt_ids = tts_tokenizer(text, return_tensors="pt").input_ids.to(device)
31
-
32
- audio = tts_model.generate(
33
- input_ids=input_ids,
34
- prompt_input_ids=prompt_ids,
35
- )
36
- sf.write(output_wav_path, audio.cpu().numpy().squeeze(), tts_model.config.sampling_rate) # Fixed: was 'model.config'
37
-
38
- return output_wav_path
39
 
40
 
41
  def progress_bar_html(label: str) -> str:
 
8
  import cv2
9
  import numpy as np
10
  from PIL import Image
11
+ from gradio_client import Client, handle_file
12
 
13
+ # Initialize TTS client
14
+ tts_client = Client("dofbi/galsenai-xtts-v2-wolof-inference")
 
15
 
 
 
 
 
 
 
16
  def tts(text):
17
+ """Generate TTS using Gradio API client"""
18
+ try:
19
+ result = tts_client.predict(
20
+ text=text,
21
+ audio_reference=handle_file('https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav'),
22
+ api_name="/predict"
23
+ )
24
+ return result
25
+ except Exception as e:
26
+ print(f"TTS API Error: {e}")
27
+ return None
 
 
 
 
28
 
29
 
30
  def progress_bar_html(label: str) -> str: