adam7788's picture
Create app.py
a1e3a48 verified
raw
history blame contribute delete
847 Bytes
import gradio as gr
from transformers import pipeline
# ุชุญู…ูŠู„ ู†ู…ูˆุฐุฌ NER ุงู„ุฅู†ุฌู„ูŠุฒูŠ
ner_pipeline = pipeline(
"token-classification",
model="dslim/bert-base-NER",
aggregation_strategy="simple"
)
def extract_entities(text):
if not text.strip():
return "Please enter some text."
entities = ner_pipeline(text)
result = ""
for ent in entities:
result += f"Word: {ent['word']} | Entity: {ent['entity_group']}\n"
return result
interface = gr.Interface(
fn=extract_entities,
inputs=gr.Textbox(
lines=5,
placeholder="Enter an English text (e.g. My name is John and I live in London)"
),
outputs=gr.Textbox(lines=12),
title="English NER Detector",
description="Testing dslim/bert-base-NER model for Named Entity Recognition"
)
interface.launch()