Install from Hugging Face; auto-download weights
Browse files- README.md +3 -2
- docs/DETAILS.md +4 -3
- hugin/synth.py +10 -2
- pyproject.toml +1 -0
README.md
CHANGED
|
@@ -30,8 +30,9 @@ Hugin is a small, fast Swedish text-to-speech model that also reads English, bot
|
|
| 30 |
## Install and use
|
| 31 |
|
| 32 |
```bash
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 35 |
python -m hugin "Hej och välkomna! Klockan är 18:30." -o hej.wav
|
| 36 |
```
|
| 37 |
|
|
|
|
| 30 |
## Install and use
|
| 31 |
|
| 32 |
```bash
|
| 33 |
+
pip install -U huggingface_hub
|
| 34 |
+
hf download codah80/futhark-hugin --local-dir futhark-hugin
|
| 35 |
+
pip install -e "./futhark-hugin[prominence]" && python -c "import stanza; stanza.download('sv', processors='tokenize,pos')"
|
| 36 |
python -m hugin "Hej och välkomna! Klockan är 18:30." -o hej.wav
|
| 37 |
```
|
| 38 |
|
docs/DETAILS.md
CHANGED
|
@@ -47,9 +47,10 @@ Regenerate them with `python tools/make_samples.py` (writes `samples/*.mp3`, nee
|
|
| 47 |
## Install
|
| 48 |
|
| 49 |
```bash
|
| 50 |
-
|
|
|
|
| 51 |
cd futhark-hugin
|
| 52 |
-
pip install -e . # torch, numpy, scipy, soundfile, num2words
|
| 53 |
pip install -e ".[server]" # optional: the small HTTP server (fastapi, uvicorn)
|
| 54 |
pip install -e ".[finetune]" # optional: hugin-finetune, to make your own voice (torchaudio, transformers)
|
| 55 |
pip install -e ".[prominence]" && python -c "import stanza; stanza.download('sv', processors='tokenize,pos')"
|
|
@@ -58,7 +59,7 @@ pip install -e ".[prominence]" && python -c "import stanza; stanza.download('sv'
|
|
| 58 |
|
| 59 |
**Prominence is optional.** With Stanza installed Hugin de-accents function words and keeps the stress on verb particles ("hon **tog** inte **upp** den"), which fixes most phrasing errors. Without Stanza it runs as before (the particle-verb list and the other rules still apply, but not the part-of-speech step). `prominence="auto"` (default) uses Stanza if it is installed, `prominence=False` / `--no-prominence` turns it off. Stanza looks for its model in `~/stanza_resources` or `$STANZA_RESOURCES_DIR`; nothing is fetched at runtime.
|
| 60 |
|
| 61 |
-
The weights live in `weights/`
|
| 62 |
|
| 63 |
## Quick start
|
| 64 |
|
|
|
|
| 47 |
## Install
|
| 48 |
|
| 49 |
```bash
|
| 50 |
+
pip install -U huggingface_hub
|
| 51 |
+
hf download codah80/futhark-hugin --local-dir futhark-hugin # or: git lfs install && git clone https://huggingface.co/codah80/futhark-hugin
|
| 52 |
cd futhark-hugin
|
| 53 |
+
pip install -e . # torch, numpy, scipy, soundfile, num2words, huggingface_hub
|
| 54 |
pip install -e ".[server]" # optional: the small HTTP server (fastapi, uvicorn)
|
| 55 |
pip install -e ".[finetune]" # optional: hugin-finetune, to make your own voice (torchaudio, transformers)
|
| 56 |
pip install -e ".[prominence]" && python -c "import stanza; stanza.download('sv', processors='tokenize,pos')"
|
|
|
|
| 59 |
|
| 60 |
**Prominence is optional.** With Stanza installed Hugin de-accents function words and keeps the stress on verb particles ("hon **tog** inte **upp** den"), which fixes most phrasing errors. Without Stanza it runs as before (the particle-verb list and the other rules still apply, but not the part-of-speech step). `prominence="auto"` (default) uses Stanza if it is installed, `prominence=False` / `--no-prominence` turns it off. Stanza looks for its model in `~/stanza_resources` or `$STANZA_RESOURCES_DIR`; nothing is fetched at runtime.
|
| 61 |
|
| 62 |
+
The weights live in `weights/` (about 180 MB). An editable install of the downloaded repository finds them on its own. If the package is installed without them, `from_pretrained()` downloads `weights/` from the Hugging Face repository once (cached by huggingface_hub; set `HUGIN_REPO` to use another copy). To use a local folder instead, set `HUGIN_WEIGHTS=/path/to/weights` or pass `path=` to `from_pretrained`.
|
| 63 |
|
| 64 |
## Quick start
|
| 65 |
|
hugin/synth.py
CHANGED
|
@@ -35,10 +35,18 @@ PUNCT = set(",.!?;:…\"'()–-")
|
|
| 35 |
HPF_HZ = 80.0
|
| 36 |
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
def default_weights_dir():
|
| 39 |
-
"""$HUGIN_WEIGHTS, else the weights/ folder next to the package (
|
|
|
|
| 40 |
env = os.environ.get("HUGIN_WEIGHTS")
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
def _fp32(sd):
|
|
|
|
| 35 |
HPF_HZ = 80.0
|
| 36 |
|
| 37 |
|
| 38 |
+
HF_REPO = os.environ.get("HUGIN_REPO", "codah80/futhark-hugin")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
def default_weights_dir():
|
| 42 |
+
"""$HUGIN_WEIGHTS, else the weights/ folder next to the package (a downloaded copy of the Hugging Face repo, editable install),
|
| 43 |
+
else download weights/ from the Hugging Face repo once (cached by huggingface_hub, about 180 MB)."""
|
| 44 |
env = os.environ.get("HUGIN_WEIGHTS")
|
| 45 |
+
if env: return Path(env)
|
| 46 |
+
local = Path(__file__).resolve().parent.parent / "weights"
|
| 47 |
+
if (local / "hugin-v0.8-b1.fp16.pt").exists(): return local
|
| 48 |
+
from huggingface_hub import snapshot_download
|
| 49 |
+
return Path(snapshot_download(HF_REPO, allow_patterns=["weights/*", "weights/**"])) / "weights"
|
| 50 |
|
| 51 |
|
| 52 |
def _fp32(sd):
|
pyproject.toml
CHANGED
|
@@ -12,6 +12,7 @@ requires-python = ">=3.9"
|
|
| 12 |
authors = [{ name = "Conny Dahlgren", email = "conny.dahlgren@devsec.se" }]
|
| 13 |
dependencies = [
|
| 14 |
"torch>=2.1",
|
|
|
|
| 15 |
"numpy",
|
| 16 |
"scipy",
|
| 17 |
"soundfile",
|
|
|
|
| 12 |
authors = [{ name = "Conny Dahlgren", email = "conny.dahlgren@devsec.se" }]
|
| 13 |
dependencies = [
|
| 14 |
"torch>=2.1",
|
| 15 |
+
"huggingface_hub>=0.25",
|
| 16 |
"numpy",
|
| 17 |
"scipy",
|
| 18 |
"soundfile",
|