Spaces:
Runtime error
Runtime error
Kornel Szabo
commited on
Commit
·
9fa0c63
1
Parent(s):
bb3c111
Add first model
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
from transformers import (
|
6 |
+
AutoTokenizer,
|
7 |
+
BertForSequenceClassification,
|
8 |
+
TextClassificationPipeline,
|
9 |
+
)
|
10 |
+
|
11 |
+
labels = [
|
12 |
+
'agency',
|
13 |
+
# 'humanComparison',
|
14 |
+
# 'hyperbole',
|
15 |
+
# 'historyComparison',
|
16 |
+
# 'unjustClaims',
|
17 |
+
# 'deepSounding',
|
18 |
+
# 'skeptics',
|
19 |
+
# 'deEmphasize',
|
20 |
+
# 'performanceNumber',
|
21 |
+
# 'inscrutable',
|
22 |
+
# 'objective'
|
23 |
+
]
|
24 |
+
|
25 |
+
models = {}
|
26 |
+
|
27 |
+
pipes = {}
|
28 |
+
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
|
30 |
+
|
31 |
+
for label in labels:
|
32 |
+
models[label] = BertForSequenceClassification.from_pretrained(
|
33 |
+
f'xt0r3/aihype_{label}-vs-rest',
|
34 |
+
)
|
35 |
+
pipe = TextClassificationPipeline(
|
36 |
+
model=models[label], tokenizer=tokenizer, return_all_scores=True
|
37 |
+
)
|
38 |
+
|
39 |
+
|
40 |
+
def predict(text):
|
41 |
+
preds = {
|
42 |
+
label: pipe[label][0][1] for label in labels
|
43 |
+
}
|
44 |
+
|
45 |
+
return preds
|
46 |
+
|
47 |
+
|
48 |
+
examples = [
|
49 |
+
"Machine Learning is at the forefront of education, replacing human jobs",
|
50 |
+
"AI model leaves scientists confused",
|
51 |
+
"This model is not really cool",
|
52 |
+
]
|
53 |
+
|
54 |
+
intf = gr.Interface(fn=predict, inputs="textbox",
|
55 |
+
outputs="label", examples=examples)
|
56 |
+
intf.launch(inline=False)
|