Spaces:
Sleeping
Sleeping
copy pasted from ChatGPT
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the NER pipeline
|
5 |
+
ner_model = pipeline("ner", model="dslim/bert-base-NER", aggregation_strategy="simple")
|
6 |
+
|
7 |
+
def extract_named_entities(text):
|
8 |
+
# Use the NER model to extract named entities
|
9 |
+
entities = ner_model(text)
|
10 |
+
# Format the output for better readability
|
11 |
+
return [{"Entity": ent["entity_group"], "Text": ent["word"], "Score": round(ent["score"], 3)} for ent in entities]
|
12 |
+
|
13 |
+
# Define the Gradio interface
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=extract_named_entities,
|
16 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
17 |
+
outputs=gr.Dataframe(headers=["Entity", "Text", "Score"], label="Named Entities"),
|
18 |
+
title="Named Entity Recognition",
|
19 |
+
description="Input some text and get the named entities (like names, locations, organizations).",
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the app
|
23 |
+
if __name__ == "__main__":
|
24 |
+
iface.launch()
|