Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files121 unmodified lines122123124125126127128129130131121 unmodified lines"""with _lock:if _embedder["emb"] is None:_embedder["emb"] = ec.Embedder(MODEL_PATH, pooling=POOLING)return _embedder["emb"]def embed_one(text):v = np.asarray(get_embedder()([PREFIX_TEXT + text])[0], dtype=np.float32)n = float(np.linalg.norm(v))121 unmodified lines122123124125126127128129130131132133134135136137138139140141142143121 unmodified lines"""with _lock:if _embedder["emb"] is None:# Letting llama.cpp pick its own thread count oversubscribes the# container's 2 vCPUs (it reads the host core count), which costs# far more than it gains on a single short sentence._embedder["emb"] = ec.Embedder(MODEL_PATH, pooling=POOLING, threads=_thread_count())return _embedder["emb"]def _thread_count():"""CPU count the container is actually allowed to use."""try:return max(1, len(os.sched_getaffinity(0))) # Linux (the Space)except AttributeError: # not Linux: macOS for local runsreturn max(1, os.cpu_count() or 1)def embed_one(text):v = np.asarray(get_embedder()([PREFIX_TEXT + text])[0], dtype=np.float32)n = float(np.linalg.norm(v))
app.py+13-1