englissi commited on
Commit
dac6347
ยท
verified ยท
1 Parent(s): 67d4906

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -36
app.py CHANGED
@@ -1,39 +1,21 @@
1
  import gradio as gr
2
- import torch
3
- from transformers import AutoTokenizer, AutoModelForPreTraining
4
- import soundfile as sf
5
-
6
- # Load the tokenizer and model for Bulgarian TTS (Text-to-Speech)
7
- tokenizer = AutoTokenizer.from_pretrained("Opit/mms_tts_bulgarian_finetuning")
8
- model = AutoModelForPreTraining.from_pretrained("Opit/mms_tts_bulgarian_finetuning")
9
-
10
- # TTS ๋ณ€ํ™˜ ํ•จ์ˆ˜ (text-to-speech conversion)
11
- def tts_generate(text):
12
- inputs = tokenizer(text, return_tensors="pt")
13
-
14
- with torch.no_grad():
15
- outputs = model(**inputs)
16
-
17
- # Convert the model outputs to audio format (you need to implement this depending on model specifics)
18
- # This will depend on how the model's outputs are structured
19
- # For now, let's assume you need a simple conversion to waveform/audio
20
-
21
- # Placeholder: Assuming `outputs` contains audio data that can be returned directly as .wav format
22
- # You might need to adjust this based on how the TTS model is structured and how it outputs speech
23
- audio = outputs['logits'] # Adjust according to your model's output structure
24
-
25
- # Return audio output (in numpy format) and the sample rate (this might be specific to your model)
26
- return audio.numpy(), 22050 # Assuming the output is sampled at 22050 Hz
27
-
28
- # Create Gradio interface
29
- iface = gr.Interface(
30
- fn=tts_generate,
31
- inputs="text",
32
- outputs="audio",
33
- title="Bulgarian TTS (Text-to-Speech)",
34
- description="Enter text to generate speech in Bulgarian."
35
  )
36
 
37
- # Run the interface
38
- if __name__ == "__main__":
39
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Hugging Face์—์„œ TTS ํŒŒ์ดํ”„๋ผ์ธ ๋กœ๋“œ
5
+ tts = pipeline("text-to-speech", model="tts-model-name") # ์ ํ•ฉํ•œ ๋ถˆ๊ฐ€๋ฆฌ์•„์–ด TTS ๋ชจ๋ธ ์ด๋ฆ„์œผ๋กœ ๋Œ€์ฒด
6
+
7
+ def generate_audio(text):
8
+ audio = tts(text)
9
+ return audio["audio"]
10
+
11
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
12
+ interface = gr.Interface(
13
+ fn=generate_audio,
14
+ inputs=gr.Textbox(lines=5, label="๋ถˆ๊ฐ€๋ฆฌ์•„์–ด ํ…์ŠคํŠธ ์ž…๋ ฅ"),
15
+ outputs=gr.Audio(label="์ƒ์„ฑ๋œ ์Œ์„ฑ"),
16
+ title="๋ถˆ๊ฐ€๋ฆฌ์•„์–ด TTS",
17
+ description="๋ถˆ๊ฐ€๋ฆฌ์•„์–ด ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์Œ์„ฑ์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  )
19
 
20
+ # ์›น ์•ฑ ์‹คํ–‰
21
+ interface.launch()