Spaces:
Runtime error
Runtime error
application file
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def interpret_pred(pred):
|
5 |
+
low_bond = -6.748472
|
6 |
+
high_bound = 6.7176056
|
7 |
+
result = "IA" if pred.argmax(dim=-1).item() == 1 else "Humain"
|
8 |
+
pred_value = pred[0][1].item()
|
9 |
+
interpreted_pred = (pred_value - low_bond) / (high_bound - low_bond)
|
10 |
+
is_ai_percent = round(100 * interpreted_pred)
|
11 |
+
return result, is_ai_percent
|
12 |
+
|
13 |
+
|
14 |
+
def main(text_sentence):
|
15 |
+
import torch
|
16 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
17 |
+
from transformers import Trainer, TrainingArguments, EarlyStoppingCallback
|
18 |
+
|
19 |
+
barthez_tokenizer = AutoTokenizer.from_pretrained("moussaKam/barthez")
|
20 |
+
model = AutoModelForSequenceClassification.from_pretrained("Anvil-ML/detecteur-ia")
|
21 |
+
|
22 |
+
input_ids = torch.tensor(
|
23 |
+
[barthez_tokenizer.encode(text_sentence, add_special_tokens=True)]
|
24 |
+
)
|
25 |
+
|
26 |
+
predict = model.forward(input_ids)[0]
|
27 |
+
|
28 |
+
result = (
|
29 |
+
"Résultat : {}.\nCe texte a {}% de chances d'avoir été généré par de l'IA"
|
30 |
+
.format(interpret_pred(predict)[0], interpret_pred(predict)[1])
|
31 |
+
)
|
32 |
+
|
33 |
+
return result
|
34 |
+
|
35 |
+
|
36 |
+
iface = gr.Interface(fn=main, inputs="text", outputs="text")
|
37 |
+
iface.launch()
|