Spaces:
Runtime error
Runtime error
Create app.py
Browse filesInitial commit
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()
|