Download app/utils/ner.py from Maulidaaa/predict: direct link, hf CLI and curl.
- Browser
- Download file 423 Bytes
-
https://huggingface.co/spaces/Maulidaaa/predict/resolve/main/app/utils/ner.py
- Command line
-
hf download hf://spaces/Maulidaaa/predict/app/utils/ner.py
-
curl -L -o ner.py https://huggingface.co/spaces/Maulidaaa/predict/resolve/main/app/utils/ner.py
423 Bytes
| from transformers import pipeline | |
| ner_pipeline = pipeline("ner", model="dslim/bert-base-NER", grouped_entities=True) | |
| def extract_ingredients(text): | |
| entities = ner_pipeline(text) | |
| ingredients = [] | |
| for ent in entities: | |
| word = ent['word'].lower().strip() | |
| if ent['entity_group'] == 'MISC' and word.isalpha() and len(word) > 2: | |
| ingredients.append(word) | |
| return list(set(ingredients)) | |