Spaces:
Sleeping
Sleeping
Initial commit
Browse files- .gitignore +2 -0
- app.py +28 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.venv
|
2 |
+
.python-version
|
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
+
from scipy.special import softmax
|
5 |
+
|
6 |
+
|
7 |
+
def predict(text):
|
8 |
+
model_name = "deepset/bert-base-german-cased-hatespeech-GermEval18Coarse"
|
9 |
+
short_score_descriptions = {0: "Kein Hasskommentar", 1: "Hasskommentar"}
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
12 |
+
model_input = tokenizer(*([text],), padding=True, return_tensors="pt")
|
13 |
+
with torch.no_grad():
|
14 |
+
output = model(**model_input)
|
15 |
+
logits = softmax(output[0][0].detach().numpy()).tolist()
|
16 |
+
return {short_score_descriptions[k]: v for k, v in enumerate(logits)}
|
17 |
+
|
18 |
+
|
19 |
+
gradio.Interface(
|
20 |
+
title="Klassifikator deutschsprachiger Hasskommentare",
|
21 |
+
inputs=[
|
22 |
+
gradio.Textbox(label="Kommentar"),
|
23 |
+
],
|
24 |
+
fn=predict,
|
25 |
+
outputs=[
|
26 |
+
gradio.Label(label="Klassifikation"),
|
27 |
+
],
|
28 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch==2.4.1
|
2 |
+
gradio==4.44.0
|
3 |
+
transformers==4.44.2
|
4 |
+
scipy==1.14.1
|