Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
971eb0b
1
Parent(s):
8e7ac23
update
Browse files- app.py +10 -6
- requirements.txt +2 -1
app.py
CHANGED
@@ -2,22 +2,26 @@ 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
|
18 |
outputs="text",
|
19 |
-
title="
|
20 |
-
description="
|
21 |
)
|
22 |
|
23 |
-
iface.launch()
|
|
|
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 |
+
|
8 |
+
@spaces.GPU # <-- required for ZeroGPU
|
9 |
def classify_tokens(text):
|
10 |
+
token_classifier = pipeline("token-classification", model="WesScivetti/SNACS_English",
|
11 |
+
aggregation_strategy="simple")
|
12 |
+
|
13 |
results = token_classifier(text)
|
14 |
output = ""
|
15 |
for entity in results:
|
16 |
output += f"{entity['word']} ({entity['entity_group']}, score={entity['score']:.2f})\n"
|
17 |
return output.strip()
|
18 |
|
|
|
19 |
iface = gr.Interface(
|
20 |
fn=classify_tokens,
|
21 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter text to be classified..."),
|
22 |
outputs="text",
|
23 |
+
title="SNACS Tagging in English",
|
24 |
+
description="SNACS Tagging in English"
|
25 |
)
|
26 |
|
27 |
+
iface.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
transformers==4.52.3
|
2 |
torch
|
3 |
-
gradio
|
|
|
|
1 |
transformers==4.52.3
|
2 |
torch
|
3 |
+
gradio
|
4 |
+
spaces
|