Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files- README.md +1 -0
- app.py +9 -18
- requirements.txt +0 -1
README.md
CHANGED
|
@@ -27,6 +27,7 @@ Native 7.5 Hz duplex streaming doesn't fit a request/response Space, so this dem
|
|
| 27 |
## Tips
|
| 28 |
|
| 29 |
- The reply is the model's full timeline, not just its speaking turns — it includes backchannels (short "mm-hm" acknowledgements) while you talk.
|
|
|
|
| 30 |
- Best voice-clone results come from a clean, single-speaker reference with no music or noise.
|
| 31 |
- `speak_first` in Advanced settings makes Haru open the conversation instead of waiting.
|
| 32 |
|
|
|
|
| 27 |
## Tips
|
| 28 |
|
| 29 |
- The reply is the model's full timeline, not just its speaking turns — it includes backchannels (short "mm-hm" acknowledgements) while you talk.
|
| 30 |
+
- After your clip the demo appends a 5-second pause, so Haru gets the floor and its spoken answer lands inside the returned timeline.
|
| 31 |
- Best voice-clone results come from a clean, single-speaker reference with no music or noise.
|
| 32 |
- `speak_first` in Advanced settings makes Haru open the conversation instead of waiting.
|
| 33 |
|
app.py
CHANGED
|
@@ -12,23 +12,6 @@ os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
|
| 12 |
|
| 13 |
import spaces # ZeroGPU: must come before torch / transformers
|
| 14 |
|
| 15 |
-
# Browsers record Opus in WebM containers, which soundfile cannot decode; the
|
| 16 |
-
# haru package falls back to an `ffmpeg` binary. The Gradio image does not ship
|
| 17 |
-
# one on PATH, so expose the static binary bundled with imageio-ffmpeg.
|
| 18 |
-
try:
|
| 19 |
-
import imageio_ffmpeg
|
| 20 |
-
|
| 21 |
-
_source = imageio_ffmpeg.get_ffmpeg_exe()
|
| 22 |
-
_bindir = "/tmp/ffmpeg-bin"
|
| 23 |
-
os.makedirs(_bindir, exist_ok=True)
|
| 24 |
-
_target = os.path.join(_bindir, "ffmpeg")
|
| 25 |
-
if not os.path.exists(_target):
|
| 26 |
-
shutil.copy2(_source, _target)
|
| 27 |
-
os.chmod(_target, 0o755)
|
| 28 |
-
os.environ["PATH"] = _bindir + os.pathsep + os.environ.get("PATH", "")
|
| 29 |
-
except Exception as _ffmpeg_error: # not fatal: WAV/FLAC/Ogg decode natively
|
| 30 |
-
print(f"[boot] ffmpeg shim not set up: {_ffmpeg_error!r}", flush=True)
|
| 31 |
-
|
| 32 |
import json
|
| 33 |
import shutil
|
| 34 |
import time
|
|
@@ -43,6 +26,7 @@ from haru.prompt import card_templates, render_card
|
|
| 43 |
|
| 44 |
MODEL_ID = "higurashi-ai/Haru-4B"
|
| 45 |
MAX_USER_SECONDS = 30 # duplex turns are short; bounds the ZeroGPU duration
|
|
|
|
| 46 |
|
| 47 |
# Character cards: built-in per-language presets shipped inside the haru package.
|
| 48 |
_TEMPLATES = card_templates()
|
|
@@ -62,7 +46,7 @@ model = load_model(MODEL_ID, device="cpu").to("cuda")
|
|
| 62 |
print("[boot] Haru-4B ready on cuda", flush=True)
|
| 63 |
|
| 64 |
|
| 65 |
-
@spaces.GPU(duration=
|
| 66 |
def converse(
|
| 67 |
user_audio,
|
| 68 |
reference_audio,
|
|
@@ -102,6 +86,11 @@ def converse(
|
|
| 102 |
limit = MAX_USER_SECONDS * SAMPLE_RATE
|
| 103 |
trimmed = len(user) > limit
|
| 104 |
user = user[:limit]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
count = max(1, -(-len(user) // frame_samples))
|
| 106 |
user = np.pad(user, (0, count * frame_samples - len(user)))
|
| 107 |
|
|
@@ -151,6 +140,8 @@ def converse(
|
|
| 151 |
text = "".join(frame.text for frame in frames).strip()
|
| 152 |
if trimmed:
|
| 153 |
text = f"(input trimmed to {MAX_USER_SECONDS} s)\n{text}"
|
|
|
|
|
|
|
| 154 |
return (SAMPLE_RATE, reply), text
|
| 155 |
|
| 156 |
|
|
|
|
| 12 |
|
| 13 |
import spaces # ZeroGPU: must come before torch / transformers
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import json
|
| 16 |
import shutil
|
| 17 |
import time
|
|
|
|
| 26 |
|
| 27 |
MODEL_ID = "higurashi-ai/Haru-4B"
|
| 28 |
MAX_USER_SECONDS = 30 # duplex turns are short; bounds the ZeroGPU duration
|
| 29 |
+
PAUSE_SECONDS = 5 # appended silence so Haru's answer lands inside the timeline
|
| 30 |
|
| 31 |
# Character cards: built-in per-language presets shipped inside the haru package.
|
| 32 |
_TEMPLATES = card_templates()
|
|
|
|
| 46 |
print("[boot] Haru-4B ready on cuda", flush=True)
|
| 47 |
|
| 48 |
|
| 49 |
+
@spaces.GPU(duration=25)
|
| 50 |
def converse(
|
| 51 |
user_audio,
|
| 52 |
reference_audio,
|
|
|
|
| 86 |
limit = MAX_USER_SECONDS * SAMPLE_RATE
|
| 87 |
trimmed = len(user) > limit
|
| 88 |
user = user[:limit]
|
| 89 |
+
# Full-duplex Haru keeps listening while you speak; a recording that ends
|
| 90 |
+
# mid-sentence cuts the timeline before Haru ever takes its turn. Appending
|
| 91 |
+
# a few seconds of silence gives it the floor, so its reply (and transcript)
|
| 92 |
+
# lands inside the returned timeline.
|
| 93 |
+
user = np.concatenate([user, np.zeros(PAUSE_SECONDS * SAMPLE_RATE, dtype=user.dtype)])
|
| 94 |
count = max(1, -(-len(user) // frame_samples))
|
| 95 |
user = np.pad(user, (0, count * frame_samples - len(user)))
|
| 96 |
|
|
|
|
| 140 |
text = "".join(frame.text for frame in frames).strip()
|
| 141 |
if trimmed:
|
| 142 |
text = f"(input trimmed to {MAX_USER_SECONDS} s)\n{text}"
|
| 143 |
+
if not text:
|
| 144 |
+
text = "… (Haru only listened this time — try again, or raise the temperature.)"
|
| 145 |
return (SAMPLE_RATE, reply), text
|
| 146 |
|
| 147 |
|
requirements.txt
CHANGED
|
@@ -1,2 +1 @@
|
|
| 1 |
haru-speech==0.1.0
|
| 2 |
-
imageio-ffmpeg
|
|
|
|
| 1 |
haru-speech==0.1.0
|
|
|