|
|
|
|
|
import spacy |
|
|
|
def load_model(): |
|
|
|
try: |
|
return spacy.load("en_core_sci_sm") |
|
except OSError: |
|
pass |
|
try: |
|
return spacy.load("en_core_web_sm") |
|
except OSError: |
|
raise RuntimeError( |
|
"No spaCy model found! Please install 'en_core_sci_sm' (preferred) or 'en_core_web_sm' " |
|
"in your Dockerfile or requirements.txt before running the app." |
|
) |
|
|
|
nlp = load_model() |
|
|
|
def extract_keywords(text: str): |
|
"""Extract biomedical or general entities from text.""" |
|
doc = nlp(text) |
|
|
|
return list(set(ent.text for ent in doc.ents if len(ent.text.strip()) > 2)) |
|
|