Can Korkut
commited on
Commit
•
1026ef9
1
Parent(s):
e07930a
Add application file
Browse files- app.py +16 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoModelForSequenceClassification
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
id2label = {0:'INSULT', 1:'OTHER', 2:'PROFANITY', 3:'RACIST', 4:'SEXIST'}
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(".")
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(".")
|
9 |
+
|
10 |
+
def predict(text):
|
11 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
12 |
+
result = id2label[int(classifier(text)[0]['label'].split('_')[-1])]
|
13 |
+
return result
|
14 |
+
|
15 |
+
iface = gr.Interface(fn=predict, inputs="text", outputs="text")
|
16 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
torchvision
|
3 |
+
transformers==4.18.0
|
4 |
+
numpy<1.24.0
|