Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,21 @@ import torch
|
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# -----------------------------
|
| 7 |
# LOAD PIPELINE (HF AUTH REQUIRED)
|
| 8 |
# -----------------------------
|
| 9 |
device = 0 if torch.cuda.is_available() else -1
|
| 10 |
-
|
| 11 |
tts_pipe = pipeline(
|
| 12 |
task="text-to-speech",
|
| 13 |
model="canopylabs/orpheus-3b-0.1-ft",
|
| 14 |
-
device=device
|
| 15 |
)
|
| 16 |
|
| 17 |
# -----------------------------
|
|
@@ -21,7 +26,11 @@ def tts_generate(text):
|
|
| 21 |
if not text.strip():
|
| 22 |
return None
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
audio = np.asarray(output["audio"], dtype=np.float32)
|
| 27 |
sr = output["sampling_rate"]
|
|
@@ -29,45 +38,44 @@ def tts_generate(text):
|
|
| 29 |
return (sr, audio)
|
| 30 |
|
| 31 |
# -----------------------------
|
| 32 |
-
# SAMPLE TEXTS WITH TAGS
|
| 33 |
# -----------------------------
|
| 34 |
SAMPLES = [
|
| 35 |
-
"Just end up crashing somewhere. <
|
| 36 |
-
"
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"<
|
| 43 |
-
"
|
| 44 |
-
"
|
| 45 |
]
|
| 46 |
|
| 47 |
# -----------------------------
|
| 48 |
-
# GRADIO
|
| 49 |
# -----------------------------
|
| 50 |
demo = gr.Interface(
|
| 51 |
fn=tts_generate,
|
| 52 |
inputs=gr.Textbox(
|
| 53 |
-
label="Enter text (use expressive tags like <
|
| 54 |
lines=5,
|
| 55 |
placeholder=SAMPLES[0],
|
| 56 |
),
|
| 57 |
outputs=gr.Audio(type="numpy", label="Generated Audio"),
|
| 58 |
title="Orpheus‑3B Expressive TTS",
|
| 59 |
description=(
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
-
"-
|
| 63 |
-
"-
|
| 64 |
-
"-
|
| 65 |
-
"
|
| 66 |
-
"
|
| 67 |
-
"Tags can appear at the **start, middle, or end** of a sentence."
|
| 68 |
),
|
| 69 |
examples=[[s] for s in SAMPLES],
|
| 70 |
)
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
-
demo.launch()
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import pipeline
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
# -----------------------------
|
| 8 |
+
# Reduce Transformers warnings
|
| 9 |
+
# -----------------------------
|
| 10 |
+
logging.getLogger("transformers").setLevel(logging.ERROR)
|
| 11 |
|
| 12 |
# -----------------------------
|
| 13 |
# LOAD PIPELINE (HF AUTH REQUIRED)
|
| 14 |
# -----------------------------
|
| 15 |
device = 0 if torch.cuda.is_available() else -1
|
|
|
|
| 16 |
tts_pipe = pipeline(
|
| 17 |
task="text-to-speech",
|
| 18 |
model="canopylabs/orpheus-3b-0.1-ft",
|
| 19 |
+
device=device
|
| 20 |
)
|
| 21 |
|
| 22 |
# -----------------------------
|
|
|
|
| 26 |
if not text.strip():
|
| 27 |
return None
|
| 28 |
|
| 29 |
+
try:
|
| 30 |
+
output = tts_pipe(text)
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print("Error:", e)
|
| 33 |
+
return None
|
| 34 |
|
| 35 |
audio = np.asarray(output["audio"], dtype=np.float32)
|
| 36 |
sr = output["sampling_rate"]
|
|
|
|
| 38 |
return (sr, audio)
|
| 39 |
|
| 40 |
# -----------------------------
|
| 41 |
+
# SAMPLE TEXTS WITH EXPRESSIVE TAGS
|
| 42 |
# -----------------------------
|
| 43 |
SAMPLES = [
|
| 44 |
+
"Just end up crashing somewhere. <laugh> No, because remember last time? You fell asleep—",
|
| 45 |
+
"Running through the grass, playing under the falling leaves. <chuckle> My sweet little kit, the—",
|
| 46 |
+
"Deal with it. I will. I'll just scowl and watch TV by myself <sigh>.",
|
| 47 |
+
"Hmm… I don't know. <laugh> This feels like a bad idea. <gasp>",
|
| 48 |
+
"I'm so tired today <yawn> but I still have so much work to do.",
|
| 49 |
+
"<cough> Wait—did you hear that? <gasp> I swear something just moved.",
|
| 50 |
+
"<whisper> Don't turn around. Just keep walking.",
|
| 51 |
+
"Ugh… <sigh> I can't believe this is happening again.",
|
| 52 |
+
"Okay okay <laughs nervously> maybe it wasn't my best decision.",
|
| 53 |
+
"I just got a new sword, ooh, it's a mighty Anduril! <groan>"
|
| 54 |
]
|
| 55 |
|
| 56 |
# -----------------------------
|
| 57 |
+
# GRADIO INTERFACE
|
| 58 |
# -----------------------------
|
| 59 |
demo = gr.Interface(
|
| 60 |
fn=tts_generate,
|
| 61 |
inputs=gr.Textbox(
|
| 62 |
+
label="Enter text (use expressive tags like <laugh>, <sigh>, <gasp>)",
|
| 63 |
lines=5,
|
| 64 |
placeholder=SAMPLES[0],
|
| 65 |
),
|
| 66 |
outputs=gr.Audio(type="numpy", label="Generated Audio"),
|
| 67 |
title="Orpheus‑3B Expressive TTS",
|
| 68 |
description=(
|
| 69 |
+
"You can add expressiveness to speech by inserting tags:\n"
|
| 70 |
+
"- <laugh>, <chuckle>: For laughter sounds\n"
|
| 71 |
+
"- <sigh>: For sighing sounds\n"
|
| 72 |
+
"- <cough>, <sniffle>: For subtle interruptions\n"
|
| 73 |
+
"- <groan>, <yawn>, <gasp>: For additional emotional expression\n\n"
|
| 74 |
+
"Tags can appear at the start, middle, or end of a sentence.\n"
|
| 75 |
+
"Example: `I can't believe it! <laugh>`"
|
|
|
|
| 76 |
),
|
| 77 |
examples=[[s] for s in SAMPLES],
|
| 78 |
)
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
+
demo.launch(ssr_mode=False)
|