| 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)) | |