Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,18 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
-
from huggingface_hub import InferenceClient
|
| 4 |
import numpy as np
|
| 5 |
-
import io
|
| 6 |
import soundfile as sf
|
|
|
|
| 7 |
|
| 8 |
# -----------------------------
|
| 9 |
-
#
|
| 10 |
# -----------------------------
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
provider="auto", # میتوانید 'fal-ai' یا 'auto' استفاده کنید
|
| 17 |
-
api_key=HF_TOKEN,
|
| 18 |
)
|
| 19 |
|
| 20 |
# -----------------------------
|
|
@@ -25,24 +23,25 @@ def tts_generate(text):
|
|
| 25 |
return None
|
| 26 |
|
| 27 |
try:
|
| 28 |
-
|
| 29 |
-
audio_bytes = client.text_to_speech(
|
| 30 |
-
text,
|
| 31 |
-
model="canopylabs/orpheus-3b-0.1-ft",
|
| 32 |
-
)
|
| 33 |
except Exception as e:
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
buffer = io.BytesIO(
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
-
return
|
| 41 |
|
| 42 |
# -----------------------------
|
| 43 |
-
#
|
| 44 |
# -----------------------------
|
| 45 |
-
|
| 46 |
"[neutral] Hello! This is a neutral English voice generated by Orpheus.",
|
| 47 |
"[expressive] I'm really excited to show you how natural this voice sounds!",
|
| 48 |
"[calm] Please relax and enjoy this calm and smooth narration.",
|
|
@@ -57,13 +56,13 @@ demo = gr.Interface(
|
|
| 57 |
fn=tts_generate,
|
| 58 |
inputs=gr.Textbox(
|
| 59 |
label="Enter text (English supported with tags)",
|
| 60 |
-
placeholder=
|
| 61 |
-
lines=4
|
| 62 |
),
|
| 63 |
-
outputs=gr.Audio(label="Generated Audio"),
|
| 64 |
-
title="Orpheus
|
| 65 |
description=(
|
| 66 |
-
"English TTS using **canopylabs/orpheus-3b-0.1-ft** via
|
| 67 |
"Supported style tags examples:\n"
|
| 68 |
"- `[neutral]`\n"
|
| 69 |
"- `[expressive]`\n"
|
|
@@ -71,9 +70,9 @@ demo = gr.Interface(
|
|
| 71 |
"- `[narration]`\n"
|
| 72 |
"- `[conversation]`\n\n"
|
| 73 |
"Example:\n"
|
| 74 |
-
"`[expressive] I'm very happy to see you today
|
| 75 |
),
|
| 76 |
-
examples=[[s] for s in
|
| 77 |
)
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import pipeline
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
import soundfile as sf
|
| 6 |
+
import io
|
| 7 |
|
| 8 |
# -----------------------------
|
| 9 |
+
# LOAD PIPELINE
|
| 10 |
# -----------------------------
|
| 11 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 12 |
+
tts_pipe = pipeline(
|
| 13 |
+
task="text-to-speech",
|
| 14 |
+
model="canopylabs/orpheus-3b-0.1-ft",
|
| 15 |
+
device=device
|
|
|
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
# -----------------------------
|
|
|
|
| 23 |
return None
|
| 24 |
|
| 25 |
try:
|
| 26 |
+
output = tts_pipe(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
+
print("Error:", e)
|
| 29 |
+
return None
|
| 30 |
+
|
| 31 |
+
audio = np.asarray(output["audio"], dtype=np.float32)
|
| 32 |
+
sr = output["sampling_rate"]
|
| 33 |
|
| 34 |
+
# Convert to bytes for Gradio Audio
|
| 35 |
+
buffer = io.BytesIO()
|
| 36 |
+
sf.write(buffer, audio, sr, format="WAV")
|
| 37 |
+
buffer.seek(0)
|
| 38 |
|
| 39 |
+
return buffer
|
| 40 |
|
| 41 |
# -----------------------------
|
| 42 |
+
# SAMPLE TEXTS WITH STYLE TAGS
|
| 43 |
# -----------------------------
|
| 44 |
+
SAMPLES = [
|
| 45 |
"[neutral] Hello! This is a neutral English voice generated by Orpheus.",
|
| 46 |
"[expressive] I'm really excited to show you how natural this voice sounds!",
|
| 47 |
"[calm] Please relax and enjoy this calm and smooth narration.",
|
|
|
|
| 56 |
fn=tts_generate,
|
| 57 |
inputs=gr.Textbox(
|
| 58 |
label="Enter text (English supported with tags)",
|
| 59 |
+
placeholder=SAMPLES[0],
|
| 60 |
+
lines=4
|
| 61 |
),
|
| 62 |
+
outputs=gr.Audio(type="file", label="Generated Audio"),
|
| 63 |
+
title="Orpheus‑3B TTS",
|
| 64 |
description=(
|
| 65 |
+
"English TTS using **canopylabs/orpheus-3b-0.1-ft** via Transformers pipeline.\n\n"
|
| 66 |
"Supported style tags examples:\n"
|
| 67 |
"- `[neutral]`\n"
|
| 68 |
"- `[expressive]`\n"
|
|
|
|
| 70 |
"- `[narration]`\n"
|
| 71 |
"- `[conversation]`\n\n"
|
| 72 |
"Example:\n"
|
| 73 |
+
"`[expressive] I'm very happy to see you today!`"
|
| 74 |
),
|
| 75 |
+
examples=[[s] for s in SAMPLES],
|
| 76 |
)
|
| 77 |
|
| 78 |
if __name__ == "__main__":
|