Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import onnxruntime as ort
|
| 3 |
+
import numpy as np
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
|
| 6 |
+
# Load ONNX model
|
| 7 |
+
session = ort.InferenceSession("assets/model.onnx", providers=["CPUExecutionProvider"])
|
| 8 |
+
|
| 9 |
+
def tts(text):
|
| 10 |
+
# Encode text to IDs (dummy simple encoding: byte values)
|
| 11 |
+
input_ids = np.array([list(text.encode("utf-8"))], dtype=np.int64)
|
| 12 |
+
|
| 13 |
+
# Run ONNX model
|
| 14 |
+
audio = session.run(None, {"text": input_ids})[0][0]
|
| 15 |
+
|
| 16 |
+
# Normalize audio if needed
|
| 17 |
+
audio = audio.astype(np.float32)
|
| 18 |
+
return (44100, audio)
|
| 19 |
+
|
| 20 |
+
def infer(text):
|
| 21 |
+
return tts(text)
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=infer,
|
| 25 |
+
inputs=gr.Textbox(label="Input text"),
|
| 26 |
+
outputs=gr.Audio(label="Output audio"),
|
| 27 |
+
title="Supertonic TTS (CPU mode)"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
iface.launch()
|