Spaces:
Runtime error
Runtime error
File size: 1,158 Bytes
fa1b58a |
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 |
import gradio as gr
def interpret_pred(pred):
low_bond = -6.748472
high_bound = 6.7176056
result = "IA" if pred.argmax(dim=-1).item() == 1 else "Humain"
pred_value = pred[0][1].item()
interpreted_pred = (pred_value - low_bond) / (high_bound - low_bond)
is_ai_percent = round(100 * interpreted_pred)
return result, is_ai_percent
def main(text_sentence):
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import Trainer, TrainingArguments, EarlyStoppingCallback
barthez_tokenizer = AutoTokenizer.from_pretrained("moussaKam/barthez")
model = AutoModelForSequenceClassification.from_pretrained("Anvil-ML/detecteur-ia")
input_ids = torch.tensor(
[barthez_tokenizer.encode(text_sentence, add_special_tokens=True)]
)
predict = model.forward(input_ids)[0]
result = (
"Résultat : {}.\nCe texte a {}% de chances d'avoir été généré par de l'IA"
.format(interpret_pred(predict)[0], interpret_pred(predict)[1])
)
return result
iface = gr.Interface(fn=main, inputs="text", outputs="text")
iface.launch() |