Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ---------------------------------------------------------------
|
2 |
+
# app.py – “TTS Showcase” (static-audio-only Streamlit demo)
|
3 |
+
# ---------------------------------------------------------------
|
4 |
+
import os
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
# ---------- 1. Page-wide settings ----------
|
8 |
+
st.set_page_config(
|
9 |
+
page_title="🔊 TTS Showcase",
|
10 |
+
page_icon="🎧",
|
11 |
+
layout="wide"
|
12 |
+
)
|
13 |
+
|
14 |
+
# ---------- 2. Demo metadata ----------
|
15 |
+
MODELS = {
|
16 |
+
"nari-labs/Dia-1.6B" : "Dia-1.6 B",
|
17 |
+
"hexgrad/Kokoro-82M" : "Kokoro 82 M",
|
18 |
+
"sesame/csm-1b" : "CSM 1 B",
|
19 |
+
"SparkAudio/Spark-TTS-0.5B" : "Spark-TTS 0.5 B",
|
20 |
+
"canopylabs/orpheus-3b-0.1-ft" : "Orpheus 3 B (FT)",
|
21 |
+
"SWivid/F5-TTS" : "F5-TTS",
|
22 |
+
"Zyphra/Zonos-v0.1-transformer" : "Zonos v0.1",
|
23 |
+
"coqui/XTTS-v2" : "XTTS-v2",
|
24 |
+
"HKUSTAudio/Llasa-3B" : "Llasa 3 B",
|
25 |
+
"amphion/MaskGCT" : "MaskGCT",
|
26 |
+
"OuteAI/Llama-OuteTTS-1.0-1B" : "Llama-Oute 1 B",
|
27 |
+
"ByteDance/MegaTTS3" : "MegaTTS 3"
|
28 |
+
}
|
29 |
+
|
30 |
+
# Folder that contains subfolders with the audio clips
|
31 |
+
SAMPLES_DIR = "samples" # <- change if yours is different
|
32 |
+
CLIP_NAME = "generated-audio.wav" # <- your agreed filename
|
33 |
+
|
34 |
+
# ---------- 3. Light CSS glow-up ----------
|
35 |
+
st.markdown(
|
36 |
+
"""
|
37 |
+
<style>
|
38 |
+
/* Wider central column & soft grey background */
|
39 |
+
.block-container { padding-top: 2rem; }
|
40 |
+
body { background: #f5f7fa; }
|
41 |
+
|
42 |
+
/* Simple card look */
|
43 |
+
.tts-card {
|
44 |
+
background: #ffffff;
|
45 |
+
border-radius: 12px;
|
46 |
+
padding: 1.2rem 1rem;
|
47 |
+
box-shadow: 0 2px 8px rgba(0,0,0,.04);
|
48 |
+
margin-bottom: 1.5rem;
|
49 |
+
}
|
50 |
+
.tts-title {
|
51 |
+
font-weight: 600;
|
52 |
+
font-size: 1.05rem;
|
53 |
+
margin-bottom: .5rem;
|
54 |
+
}
|
55 |
+
audio { width: 100%; } /* Full-width players */
|
56 |
+
</style>
|
57 |
+
""",
|
58 |
+
unsafe_allow_html=True
|
59 |
+
)
|
60 |
+
|
61 |
+
# ---------- 4. Header & optional quick-filter ----------
|
62 |
+
st.title("🎙️ Open-Source Text to Speech Model Gallery")
|
63 |
+
|
64 |
+
with st.expander("ℹ️ About this demo", expanded=True):
|
65 |
+
st.write(
|
66 |
+
"""
|
67 |
+
* 12 popular TTS checkpoints, each with a single **_pre-synthesised_** sample
|
68 |
+
* Nothing heavy runs in your browser – it’s basically an audio gallery
|
69 |
+
* All clips should live under `samples/<repo-slug>/generated-audio.wav`
|
70 |
+
"""
|
71 |
+
)
|
72 |
+
|
73 |
+
filter_text = st.text_input(
|
74 |
+
"Filter models… (e.g. “coqui” or “3B”)",
|
75 |
+
placeholder="Leave blank to show all",
|
76 |
+
label_visibility="collapsed"
|
77 |
+
).lower().strip()
|
78 |
+
|
79 |
+
# ---------- 5. Render cards in a responsive 3-column grid ----------
|
80 |
+
COLS_PER_ROW = 3
|
81 |
+
cols = st.columns(COLS_PER_ROW)
|
82 |
+
|
83 |
+
def repo_to_slug(repo: str) -> str:
|
84 |
+
"""huggingface/xxx -> huggingface_xxx (for folder naming)."""
|
85 |
+
return repo.replace("/", "_")
|
86 |
+
|
87 |
+
visible_models = [
|
88 |
+
(repo, nice_name)
|
89 |
+
for repo, nice_name in MODELS.items()
|
90 |
+
if filter_text in repo.lower() or filter_text in nice_name.lower()
|
91 |
+
]
|
92 |
+
|
93 |
+
if not visible_models:
|
94 |
+
st.warning("No models match that filter.")
|
95 |
+
else:
|
96 |
+
for idx, (repo, display_name) in enumerate(visible_models):
|
97 |
+
with cols[idx % COLS_PER_ROW]:
|
98 |
+
with st.container():
|
99 |
+
st.markdown("<div class='tts-card'>", unsafe_allow_html=True)
|
100 |
+
st.markdown(f"<div class='tts-title'>🎧 {display_name}</div>", unsafe_allow_html=True)
|
101 |
+
|
102 |
+
# Resolved path: samples/<repo-as-slug>/generated-audio.wav
|
103 |
+
audio_path = os.path.join(SAMPLES_DIR, repo_to_slug(repo), CLIP_NAME)
|
104 |
+
if os.path.isfile(audio_path):
|
105 |
+
st.audio(audio_path)
|
106 |
+
else:
|
107 |
+
st.error("Sample clip not found 🤷♂️")
|
108 |
+
|
109 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
110 |
+
|
111 |
+
# ---------- 6. Footer ----------
|
112 |
+
st.markdown("---")
|
113 |
+
st.caption("Crafted with ❤️ using Streamlit 1.35")
|