PeterPinetree commited on
Commit
1269a6e
·
verified ·
1 Parent(s): 2376db2

Create app.py

Browse files

Initial commit

Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoProcessor, AutoModel
4
+
5
+ # Load Kokoro TTS Model
6
+ device = "cuda" if torch.cuda.is_available() else "cpu"
7
+ model_name = "hexgrad/Kokoro-82M"
8
+ model = AutoModel.from_pretrained(model_name).to(device)
9
+ processor = AutoProcessor.from_pretrained(model_name)
10
+
11
+ def text_to_speech(text):
12
+ """Convert input text to speech using Kokoro TTS"""
13
+ inputs = processor(text, return_tensors="pt").to(device)
14
+ with torch.no_grad():
15
+ output = model.generate(**inputs)
16
+ return output.cpu().numpy()
17
+
18
+ # Gradio Interface
19
+ description = "Enter text and listen to the Kokoro TTS model read it aloud."
20
+
21
+ demo = gr.Interface(
22
+ fn=text_to_speech,
23
+ inputs=gr.Textbox(placeholder="Type something here..."),
24
+ outputs=gr.Audio(type="numpy"),
25
+ title="Kokoro TTS - Text-to-Speech",
26
+ description=description,
27
+ )
28
+
29
+ demo.launch()