Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import re
|
3 |
+
import os
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
AUTH_TOKEN = os.environ["AUTH_TOKEN"]
|
7 |
+
|
8 |
+
classifier = pipeline('text-classification',
|
9 |
+
model="djsull/kobigbird-hate-multi-label_short",
|
10 |
+
use_auth_token=AUTH_TOKEN,
|
11 |
+
return_all_scores=True,
|
12 |
+
function_to_apply='sigmoid',
|
13 |
+
)
|
14 |
+
|
15 |
+
def predict(text):
|
16 |
+
query = text
|
17 |
+
cleanr = re.compile('<.*?>')
|
18 |
+
query = re.sub(cleanr, '', query)
|
19 |
+
query = ' '.join(re.sub('[^가-힣a-zA-Z0-9 ]', ' ', query).split())
|
20 |
+
|
21 |
+
result = classifier(query)[0]
|
22 |
+
|
23 |
+
res = []
|
24 |
+
for i in range(len(result)):
|
25 |
+
if result[i]['score'] > 0.1:
|
26 |
+
res.append(result[i]['label'])
|
27 |
+
|
28 |
+
res = ', '.join(res)
|
29 |
+
|
30 |
+
return res
|
31 |
+
|
32 |
+
gr.Interface(
|
33 |
+
predict,
|
34 |
+
inputs=gr.inputs.Textbox(label="Type anything"),
|
35 |
+
outputs=gr.outputs.Textbox(label="labels"),
|
36 |
+
title="curse classification",
|
37 |
+
).launch()
|