Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,2 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
def ner_interface(text):
|
| 5 |
+
"""
|
| 6 |
+
Gradio interface function for NER pipeline.
|
| 7 |
+
"""
|
| 8 |
+
pipe = pipeline("ner", model="NbAiLab/nb-bert-base-ner", aggregation_strategy="simple")
|
| 9 |
+
results = pipe(text)
|
| 10 |
+
df_results = pd.DataFrame(results)
|
| 11 |
+
return df_results
|
| 12 |
+
|
| 13 |
+
# Create the Gradio interface
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=ner_interface,
|
| 16 |
+
inputs=gr.Textbox(lines=10, label="Enter text for NER"),
|
| 17 |
+
outputs=gr.DataFrame(label="Extracted Entities"),
|
| 18 |
+
title="Named Entity Recognition (NER) Pipeline",
|
| 19 |
+
description="Extracts entities (like persons, organizations, and locations) from text using the NbAiLab/nb-bert-base-ner model."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch the interface
|
| 23 |
+
iface.launch()
|