Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from dia.model import Dia
|
| 4 |
+
|
| 5 |
+
# Use CPU
|
| 6 |
+
device = torch.device("cpu")
|
| 7 |
+
|
| 8 |
+
# Load the model once
|
| 9 |
+
model = Dia.from_pretrained(
|
| 10 |
+
"nari-labs/Dia-1.6B-0626", compute_dtype="float32", device=device
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def generate_audio(text):
|
| 14 |
+
output = model.generate(text, use_torch_compile=False, verbose=False)
|
| 15 |
+
output_path = "output.mp3"
|
| 16 |
+
model.save_audio(output_path, output)
|
| 17 |
+
return output_path
|
| 18 |
+
|
| 19 |
+
# Gradio UI
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=generate_audio,
|
| 22 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter dialogue here..."),
|
| 23 |
+
outputs=gr.Audio(type="filepath"),
|
| 24 |
+
title="Dia - Text to Dialogue",
|
| 25 |
+
description="Enter dialogue formatted like [S1] Hello. [S2] Hi there!",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
iface.launch()
|