Spaces:
Runtime error
Runtime error
File size: 2,039 Bytes
9fa0c63 b649da4 9fa0c63 e74c2c9 9fa0c63 e74c2c9 9fa0c63 e74c2c9 1cd0306 e74c2c9 1cd0306 9fa0c63 b649da4 9fa0c63 b649da4 9fa0c63 816b01d 9fa0c63 a91672a 9fa0c63 a91672a 9fa0c63 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import json
from pathlib import Path
import gradio as gr
from transformers import (
AutoTokenizer,
AutoModelForSequenceClassification,
TextClassificationPipeline,
)
labels = [
# 'agency',
# 'humanComparison',
# 'hyperbole',
# 'historyComparison',
# 'unjustClaims',
# 'deepSounding',
# 'skeptics',
# 'deEmphasize',
# 'performanceNumber',
# 'inscrutable',
# 'objective'
"agency",
# "suggestiveImagery",
"comparisonWithHumanIntelligence",
"comparisonWithHumanSkills",
"hyperbole",
"uncriticalHistoryComparison",
"unjustifiedClaimsAboutFuture",
"falseClaimsAboutProgress",
"incorrectClaimsAboutStudyReport",
"deepSoundingTermsForBanalities",
"treatingSpokespeopleAsNeutral",
"repeatingPRTerms",
"noDiscussionOfLimitations",
"deEmphasizingLimitations",
"limitationsAddressedBySkeptics",
"downplayingHumanLabour",
"performanceNumbersWithoutCaveats",
# "inscrutability",
]
models = {}
pipes = {}
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
for label in labels:
models[label] = AutoModelForSequenceClassification.from_pretrained(
f'xt0r3/aihype_{label}-vs-rest',
)
pipes[label] = TextClassificationPipeline(
model=models[label], tokenizer=tokenizer, top_k=None,
)
def predict(text):
preds = {}
for label in labels:
pred_array = pipes[label](text)[0]
for pred in pred_array:
if pred['label'] == 'LABEL_1':
preds[label] = pred['score']
return preds
examples = [
"Machine Learning is at the forefront of education, replacing human jobs",
"Machine Learning is at the forefront of education, but it isn't replacing human jobs just yet",
"AI model leaves scientists confused",
"Tech company unveils radical new assistant that will 'do everything for you'",
]
intf = gr.Interface(fn=predict, inputs="textbox",
outputs="label", examples=examples)
intf.launch(inline=False)
|