Download app.py from matrixy/paradee: direct link, hf CLI and curl.
- Browser
- Download file 8.93 kB
-
https://huggingface.co/spaces/matrixy/paradee/resolve/main/app.py
- Command line
-
hf download hf://spaces/matrixy/paradee/app.py
-
curl -L -o app.py https://huggingface.co/spaces/matrixy/paradee/resolve/main/app.py
8.93 kB
| import spaces # noqa: F401 (kept first so the import order holds if a torch dep ever sneaks in) | |
| import json | |
| import os | |
| import time | |
| import gradio as gr | |
| import numpy as np | |
| import soundfile as sf | |
| from paradee_tts import Paradee, SAMPLE_RATE | |
| DESCRIPTION = """ | |
| <div style="text-align: center; max-width: 800px; margin: 0 auto;"> | |
| <h1 style="font-size: 1.8rem; margin-bottom: 0.3rem;">Paradee 🐦 — 8M-parameter text-to-speech</h1> | |
| <p style="font-size: 1.0rem; opacity: 0.85; margin-top: 0;"> | |
| Distilled from <a href="https://huggingface.co/hexgrad/Kokoro-82M">Kokoro-82M</a> into an 8.07M-parameter single-voice model (voice <code>af_heart</code>). | |
| The int8 ONNX file is 9 MB and runs ~18× faster than real time on one CPU thread — this Space synthesizes on CPU, no GPU needed. | |
| </p> | |
| <p style="font-size: 0.9rem; opacity: 0.7; margin-top: 0.3rem;"> | |
| <a href="https://huggingface.co/sahilmahendrakar/Paradee-8M-v1.0">Model</a> · | |
| <a href="https://github.com/sahilmahendrakar/paradee">GitHub</a> · | |
| <a href="https://arxiv.org/abs/2610.06817">Paper</a> | |
| </p> | |
| </div> | |
| """ | |
| # Authors' own example sentences: the README quick-start line, then the five | |
| # held-out benchmark sentences from the model card (samples/sentences.txt). | |
| EXAMPLES = [ | |
| ["Paradee is a small voice that runs anywhere.", 1.0], | |
| ["As of August 2015, there were 169 proposed targets for these goals and 304 proposed indicators to show compliance.", 1.0], | |
| ["White dwarf stars, if they have a near companion, may then become Type Ia supernovae.", 1.0], | |
| ["Harvey ended with a century on his Ashes debut, scoring 112 from 183 balls in an innings noted for powerful driving on both sides of the wicket.", 1.0], | |
| ["In 1997 Hurlbut's career focused on light as applied to photography and film, and he owned a lighting business in Pasadena, California.", 1.0], | |
| ["The quirky xylophone cost 1,234 dollars, said Mrs. Zzyzx.", 1.2], | |
| ] | |
| CHAR_LIMIT = 2000 | |
| print("Loading Paradee (downloads the 9 MB int8 ONNX model on first run)...") | |
| t0 = time.perf_counter() | |
| TTS = Paradee() # reference path: onnxruntime CPUExecutionProvider, one thread | |
| print(f"Paradee loaded in {time.perf_counter() - t0:.1f}s") | |
| def generate(text: str, speed: float = 1.0, progress=gr.Progress()): | |
| """Convert English text to speech with the 8M-parameter Paradee model (voice af_heart). | |
| Args: | |
| text: English text to speak. Long text is read one sentence at a time. | |
| speed: Speaking rate; 1.0 is normal, higher is faster. | |
| progress: Gradio progress bar. | |
| Returns: | |
| Tuple of (audio as (sample_rate, waveform) for gr.Audio, phoneme string, status line). | |
| """ | |
| text = (text or "").strip() | |
| if not text: | |
| raise gr.Error("Please enter some text for Paradee to read.") | |
| if len(text) > CHAR_LIMIT: | |
| text = text[:CHAR_LIMIT] | |
| gr.Warning(f"Text truncated to the first {CHAR_LIMIT} characters.") | |
| speed = float(np.clip(speed, 0.5, 2.0)) | |
| t0 = time.perf_counter() | |
| try: | |
| audio = TTS(text, speed=speed) | |
| except Exception as e: | |
| raise gr.Error(f"Synthesis failed: {e}") | |
| elapsed = time.perf_counter() - t0 | |
| if audio.size == 0: | |
| raise gr.Error("No speech was produced — try different wording.") | |
| phonemes = TTS.phonemize(_first_sentence(text)) | |
| secs = len(audio) / SAMPLE_RATE | |
| status = ( | |
| f"**{secs:.1f}s of audio** in {elapsed:.2f}s on CPU " | |
| f"({secs / elapsed:.1f}× real time) · 24 kHz" | |
| ) | |
| return (SAMPLE_RATE, audio), phonemes, status | |
| def _first_sentence(text: str) -> str: | |
| import re | |
| for sentence in re.split(r"(?<=[.!?…])\s+|\n+", text.strip()): | |
| if sentence.strip(): | |
| return sentence | |
| return text | |
| def tokenize(text: str) -> str: | |
| """Show how misaki (Kokoro's own G2P) turns the first sentence into phonemes. | |
| Args: | |
| text: English text to phonemize. | |
| Returns: | |
| The phoneme string Paradee would synthesize. | |
| """ | |
| text = (text or "").strip() | |
| if not text: | |
| return "" | |
| return TTS.phonemize(_first_sentence(text)) | |
| CSS = """ | |
| #col-container { max-width: 900px; margin: 0 auto; } | |
| .dark .gradio-container { color: var(--body-text-color); } | |
| """ | |
| with gr.Blocks(title="Paradee TTS") as demo: | |
| with gr.Column(elem_id="col-container"): | |
| gr.Markdown(DESCRIPTION) | |
| with gr.Tabs(): | |
| with gr.Tab("Generate"): | |
| audio_out = gr.Audio( | |
| label="Speech (24 kHz)", interactive=False, streaming=False, autoplay=True | |
| ) | |
| with gr.Row(): | |
| text_in = gr.Textbox( | |
| label="Text", | |
| placeholder="Type something for Paradee to say…", | |
| lines=4, | |
| max_lines=10, | |
| scale=5, | |
| ) | |
| with gr.Column(scale=1): | |
| speed = gr.Slider( | |
| minimum=0.5, maximum=2.0, value=1.0, step=0.05, | |
| label="Speed", info="1.0 = normal", | |
| ) | |
| run_btn = gr.Button("Speak", variant="primary") | |
| status_out = gr.Markdown() | |
| with gr.Accordion("Phonemes (misaki G2P)", open=False): | |
| phoneme_out = gr.Textbox( | |
| label="Phonemes for the first sentence", | |
| interactive=False, | |
| info="Paradee was trained on misaki's spelling of English — this is exactly what the model sees.", | |
| ) | |
| tokenize_btn = gr.Button("Phonemize only", variant="secondary") | |
| gr.Examples( | |
| examples=EXAMPLES, | |
| inputs=[text_in, speed], | |
| outputs=[audio_out, phoneme_out, status_out], | |
| fn=generate, | |
| cache_examples=True, | |
| cache_mode="lazy", | |
| label="Examples (the authors' quick-start line and the five held-out benchmark sentences)", | |
| ) | |
| with gr.Tab("Paradee vs. teacher (Kokoro-82M)"): | |
| gr.Markdown( | |
| "The model card's five held-out sentences, as synthesized by **Paradee (8.07M)** " | |
| "and its teacher **Kokoro-82M**. Clips come straight from " | |
| "[the model card](https://huggingface.co/sahilmahendrakar/Paradee-8M-v1.0#samples) — no cherry-picking." | |
| ) | |
| sentence_texts = [ | |
| "As of August 2015, there were 169 proposed targets for these goals and 304 proposed indicators to show compliance.", | |
| "White dwarf stars, if they have a near companion, may then become Type Ia supernovae.", | |
| "According to Herodotus, this was because they had decided in council that they could not beat the Allies in a naval battle.", | |
| "In 1997 Hurlbut's career focused on light as applied to photography and film, and he owned a lighting business in Pasadena, California.", | |
| "Harvey ended with a century on his Ashes debut, scoring 112 from 183 balls in an innings noted for powerful driving on both sides of the wicket.", | |
| ] | |
| for i, sent in enumerate(sentence_texts, start=1): | |
| with gr.Accordion(f"Sentence {i}", open=(i == 1)): | |
| gr.Markdown(f"> {sent}") | |
| with gr.Row(): | |
| gr.Audio( | |
| f"samples/{i}_paradee.wav", | |
| label="Paradee (8.07M)", | |
| interactive=False, | |
| ) | |
| gr.Audio( | |
| f"samples/{i}_kokoro.wav", | |
| label="Kokoro-82M (teacher)", | |
| interactive=False, | |
| ) | |
| gr.Markdown( | |
| "<p style='font-size: 0.8rem; opacity: 0.6; text-align: center; margin-top: 1rem;'>" | |
| "Paradee © Sahil Mahendrakar, Apache-2.0. Distilled from Kokoro-82M (hexgrad). " | |
| "Benchmark sentences from WikiText-103. This Space vendors the reference " | |
| "<a href='https://github.com/sahilmahendrakar/paradee/blob/main/paradee/tts.py'>paradee/tts.py</a> unmodified." | |
| "</p>" | |
| ) | |
| run_btn.click( | |
| generate, | |
| inputs=[text_in, speed], | |
| outputs=[audio_out, phoneme_out, status_out], | |
| api_name="generate", | |
| concurrency_limit=4, | |
| ) | |
| tokenize_btn.click(tokenize, inputs=[text_in], outputs=[phoneme_out], api_name="phonemize") | |
| demo.launch( | |
| theme=gr.themes.Citrus(), | |
| css=CSS, | |
| mcp_server=True, | |
| allowed_paths=[os.path.join(os.path.dirname(os.path.abspath(__file__)), "samples")], | |
| ) |