AI-Hype-Monitor / app.py
Kornel Szabo
Add first model
9fa0c63
raw
history blame
1.18 kB
import json
from pathlib import Path
import gradio as gr
from transformers import (
AutoTokenizer,
BertForSequenceClassification,
TextClassificationPipeline,
)
labels = [
'agency',
# 'humanComparison',
# 'hyperbole',
# 'historyComparison',
# 'unjustClaims',
# 'deepSounding',
# 'skeptics',
# 'deEmphasize',
# 'performanceNumber',
# 'inscrutable',
# 'objective'
]
models = {}
pipes = {}
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
for label in labels:
models[label] = BertForSequenceClassification.from_pretrained(
f'xt0r3/aihype_{label}-vs-rest',
)
pipe = TextClassificationPipeline(
model=models[label], tokenizer=tokenizer, return_all_scores=True
)
def predict(text):
preds = {
label: pipe[label][0][1] for label in labels
}
return preds
examples = [
"Machine Learning is at the forefront of education, replacing human jobs",
"AI model leaves scientists confused",
"This model is not really cool",
]
intf = gr.Interface(fn=predict, inputs="textbox",
outputs="label", examples=examples)
intf.launch(inline=False)