Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ class TextChunker:
|
|
| 32 |
|
| 33 |
sentences = sent_tokenize(text)
|
| 34 |
if len(sentences) <= 1:
|
| 35 |
-
return [text] if
|
| 36 |
|
| 37 |
contextualized = self._add_context(sentences, context_window)
|
| 38 |
embeddings = self.model.encode(contextualized,batch_size=32,show_progress_bar=False)
|
|
@@ -63,8 +63,8 @@ class TextChunker:
|
|
| 63 |
|
| 64 |
|
| 65 |
def _estimate_tokens(self, text: str) -> int:
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
def _split_oversized(self, chunk: str, max_tokens: int, sent_tokenize) -> List[str]:
|
| 70 |
"""Split a chunk that exceeds max_tokens at sentence boundaries."""
|
|
@@ -208,7 +208,7 @@ async def lifespan(app: FastAPI):
|
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
-
|
| 212 |
print("All models ready!")
|
| 213 |
yield
|
| 214 |
models.clear()
|
|
@@ -302,9 +302,7 @@ class BatchNLIResult(BaseModel):
|
|
| 302 |
# ---------- Endpoints ----------
|
| 303 |
@app.get("/health")
|
| 304 |
def health():
|
| 305 |
-
return {"status": "ok",
|
| 306 |
-
"models_loaded": list(models.keys()),
|
| 307 |
-
}
|
| 308 |
|
| 309 |
|
| 310 |
@app.get("/memory")
|
|
|
|
| 32 |
|
| 33 |
sentences = sent_tokenize(text)
|
| 34 |
if len(sentences) <= 1:
|
| 35 |
+
return [text] if text.strip() else []
|
| 36 |
|
| 37 |
contextualized = self._add_context(sentences, context_window)
|
| 38 |
embeddings = self.model.encode(contextualized,batch_size=32,show_progress_bar=False)
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
def _estimate_tokens(self, text: str) -> int:
|
| 66 |
+
# Fast approximation: 1 token ≈ 4 chars for English legal text
|
| 67 |
+
return len(text) // 4
|
| 68 |
|
| 69 |
def _split_oversized(self, chunk: str, max_tokens: int, sent_tokenize) -> List[str]:
|
| 70 |
"""Split a chunk that exceeds max_tokens at sentence boundaries."""
|
|
|
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
+
|
| 212 |
print("All models ready!")
|
| 213 |
yield
|
| 214 |
models.clear()
|
|
|
|
| 302 |
# ---------- Endpoints ----------
|
| 303 |
@app.get("/health")
|
| 304 |
def health():
|
| 305 |
+
return {"status": "ok",}
|
|
|
|
|
|
|
| 306 |
|
| 307 |
|
| 308 |
@app.get("/memory")
|