Spaces:
Paused
Paused
Commit ·
62431ce
1
Parent(s): a8be4d0
Optimize memory footprint for Render Free Tier
Browse files- ner_utils.py +15 -7
- render.yaml +7 -2
ner_utils.py
CHANGED
|
@@ -21,12 +21,19 @@ First run will download the model (~400MB) -- this is normal, only happens once.
|
|
| 21 |
|
| 22 |
from transformers import pipeline
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
CONFIDENCE_THRESHOLD = 0.50 # lowered slightly -- was excluding useful entities like food/drug terms
|
| 32 |
|
|
@@ -42,7 +49,8 @@ def extract_entities(claim_text: str) -> list[dict]:
|
|
| 42 |
...
|
| 43 |
]
|
| 44 |
"""
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
entities = []
|
| 48 |
for ent in raw_entities:
|
|
|
|
| 21 |
|
| 22 |
from transformers import pipeline
|
| 23 |
|
| 24 |
+
_ner_pipeline = None
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _get_pipeline():
|
| 28 |
+
global _ner_pipeline
|
| 29 |
+
if _ner_pipeline is None:
|
| 30 |
+
_ner_pipeline = pipeline(
|
| 31 |
+
"token-classification",
|
| 32 |
+
model="d4data/biomedical-ner-all",
|
| 33 |
+
aggregation_strategy="simple", # merges sub-word tokens into full entity words
|
| 34 |
+
)
|
| 35 |
+
return _ner_pipeline
|
| 36 |
+
|
| 37 |
|
| 38 |
CONFIDENCE_THRESHOLD = 0.50 # lowered slightly -- was excluding useful entities like food/drug terms
|
| 39 |
|
|
|
|
| 49 |
...
|
| 50 |
]
|
| 51 |
"""
|
| 52 |
+
pipe = _get_pipeline()
|
| 53 |
+
raw_entities = pipe(claim_text)
|
| 54 |
|
| 55 |
entities = []
|
| 56 |
for ent in raw_entities:
|
render.yaml
CHANGED
|
@@ -2,11 +2,16 @@ services:
|
|
| 2 |
- type: web
|
| 3 |
name: verimed-ai
|
| 4 |
env: python
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
envVars:
|
| 8 |
- key: PYTHON_VERSION
|
| 9 |
value: 3.11.9
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
- key: FLASK_SECRET_KEY
|
| 11 |
generateValue: true
|
| 12 |
- key: GROQ_API_KEY
|
|
|
|
| 2 |
- type: web
|
| 3 |
name: verimed-ai
|
| 4 |
env: python
|
| 5 |
+
plan: free
|
| 6 |
+
buildCommand: "pip install --no-cache-dir -r requirements.txt && python ingest.py"
|
| 7 |
+
startCommand: "gunicorn app:app --bind 0.0.0.0:$PORT --workers 1 --threads 2 --timeout 120"
|
| 8 |
envVars:
|
| 9 |
- key: PYTHON_VERSION
|
| 10 |
value: 3.11.9
|
| 11 |
+
- key: OMP_NUM_THREADS
|
| 12 |
+
value: "1"
|
| 13 |
+
- key: MKL_NUM_THREADS
|
| 14 |
+
value: "1"
|
| 15 |
- key: FLASK_SECRET_KEY
|
| 16 |
generateValue: true
|
| 17 |
- key: GROQ_API_KEY
|