WesScivetti commited on
Commit
9974890
·
1 Parent(s): ead0d2c

Add app file

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pipeline (token classification)
5
+ token_classifier = pipeline("token-classification", model="WesScivetti/SNACS_English", aggregation_strategy="simple")
6
+
7
+ def classify_tokens(text):
8
+ results = token_classifier(text)
9
+ output = ""
10
+ for entity in results:
11
+ output += f"{entity['word']} ({entity['entity_group']}, score={entity['score']:.2f})\n"
12
+ return output.strip()
13
+
14
+ # Gradio Interface
15
+ iface = gr.Interface(
16
+ fn=classify_tokens,
17
+ inputs=gr.Textbox(lines=4, placeholder="Enter a sentence..."),
18
+ outputs="text",
19
+ title="Token Classification with Transformers",
20
+ description="Named Entity Recognition (NER) using Hugging Face Transformers"
21
+ )
22
+
23
+ iface.launch()