dlaima commited on
Commit
226b03c
·
verified ·
1 Parent(s): dfcd1ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the NER pipeline from Hugging Face
5
+ ner_pipeline = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english")
6
+
7
+ # Function to perform NER
8
+ def perform_ner(text):
9
+ # Run NER on the input text
10
+ results = ner_pipeline(text)
11
+
12
+ # Format results for better readability
13
+ formatted_results = [
14
+ {
15
+ "Entity": result["entity"],
16
+ "Word": result["word"],
17
+ "Score": round(result["score"], 4),
18
+ "Start": result["start"],
19
+ "End": result["end"]
20
+ }
21
+ for result in results
22
+ ]
23
+ return formatted_results
24
+
25
+ # Define the Gradio interface
26
+ title = "Named Entity Recognition (NER) App"
27
+ description = "Enter text below to extract named entities like persons, organizations, and locations using a Hugging Face model."
28
+
29
+ interface = gr.Interface(
30
+ fn=perform_ner, # The function to process input
31
+ inputs=gr.Textbox(lines=5, label="Input Text"), # Text input for the user
32
+ outputs=gr.Dataframe( # Display results as a table
33
+ headers=["Entity", "Word", "Score", "Start", "End"],
34
+ label="Recognized Entities"
35
+ ),
36
+ title=title,
37
+ description=description
38
+ )
39
+
40
+ # Launch the Gradio app
41
+ interface.launch()