Spaces:
Sleeping
Sleeping
Commit
·
d37a37c
1
Parent(s):
950136d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
model_name = 'gngpostalsrvc/COHeN'
|
2 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
3 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
4 |
+
cls_explainer = SequenceClassificationExplainer(model, tokenizer)
|
5 |
+
|
6 |
+
pattern = re.compile("[^\s\u05d0-\u05ea\u05b0-\u05bc\u05be\u05c1\u05c2\u05c7]")
|
7 |
+
|
8 |
+
def predict(text):
|
9 |
+
text = " ".join([word for word in text.split() if word not in ['\u05e1', '\u05e4', '']])
|
10 |
+
text = re.sub(pattern, "", text)
|
11 |
+
text = sbl_normalization(text)
|
12 |
+
word_attributions = cls_explainer(text)
|
13 |
+
html = cls_explainer.visualize()
|
14 |
+
return html
|
15 |
+
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=predict,
|
18 |
+
inputs='text',
|
19 |
+
outputs='html',
|
20 |
+
)
|
21 |
+
|
22 |
+
iface.launch()
|