Spaces:
Paused
Paused
Malina
Claude Fable 5.1
v0.90: scoped single-use tokens, hardened link fetch, 45-minute cap, whole-video digest, one classification call, no OCR
1d697a7 Download utils.py from NextNeural/NINA: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/NextNeural/NINA/resolve/main/utils.py
- Command line
-
hf download hf://spaces/NextNeural/NINA/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/NextNeural/NINA/resolve/main/utils.py
1.43 kB
| import math | |
| import numpy as np | |
| def _build_chunk(segs: list[dict], embs: list[np.ndarray]) -> dict: | |
| total = sum(max(s["end"] - s["start"], 0.1) for s in segs) | |
| logp = sum(s.get("logprob", 0.0) * max(s["end"] - s["start"], 0.1) | |
| for s in segs) / total | |
| stacked = np.stack(embs) | |
| return { | |
| "text": " ".join(s["text"] for s in segs), | |
| "start": segs[0]["start"], | |
| "end": segs[-1]["end"], | |
| "logprob": round(logp, 3), | |
| "emb": np.mean(stacked, axis=0), | |
| "seg_embs": stacked, # per-segment embeddings for MaxSim retrieval | |
| "seg_texts": [s["text"] for s in segs], # per-segment texts for cross-encoder scoring | |
| } | |
| def _cosine(a: np.ndarray, b: np.ndarray) -> float: | |
| return float(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b) + 1e-9)) | |
| def _sigmoid(x: float) -> float: | |
| return 1.0 / (1.0 + math.exp(-float(x))) | |
| def fmt_time(s: float) -> str: | |
| """m:ss, or h:mm:ss past an hour. The old m:ss.cc (with minutes running past 59) | |
| clashed with the [m:ss] the prompts ask for, so cited times came back reformatted.""" | |
| total = max(0, int(round(float(s or 0.0)))) | |
| h, rem = divmod(total, 3600) | |
| m, sec = divmod(rem, 60) | |
| return f"{h}:{m:02d}:{sec:02d}" if h else f"{m}:{sec:02d}" | |
| def conf_bar(c: float) -> str: | |
| f = round(c * 10) | |
| return "█" * f + "░" * (10 - f) | |