Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Charger le modèle et le tokenizer
|
6 |
+
model_name = "papasega/finetune_Distilbert_SST_Avalinguo_Fluency"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Fonction de prédiction
|
11 |
+
def predict_fluency(text):
|
12 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
13 |
+
logits = model(**inputs).logits
|
14 |
+
probs = torch.softmax(logits, dim=1)
|
15 |
+
label = torch.argmax(probs, dim=1).item()
|
16 |
+
if label == 0:
|
17 |
+
return "Low Fluency"
|
18 |
+
else:
|
19 |
+
return "High Fluency"
|
20 |
+
|
21 |
+
iface = gr.Interface(fn=predict_fluency,
|
22 |
+
inputs="text",
|
23 |
+
outputs="text",
|
24 |
+
description="Ce modèle est un modèle de classification de la fluence de l'utilisateur suivant le texte.",
|
25 |
+
examples=[
|
26 |
+
["Engineer, Yeah, indeed, you know that the lady has a Phd. It's the 1st.",
|
27 |
+
"Engineer, Yeah, indeed, you know that the lady has a Phd. It's the 1st."],
|
28 |
+
[ "Oh, how was brown for you?",
|
29 |
+
"Oh, how was brown for you?"],
|
30 |
+
[ "Now they can.",
|
31 |
+
"Now they can."],
|
32 |
+
[ "But kind of plastics like growing more social consciousness, right?",
|
33 |
+
"But kind of plastics like growing more social consciousness, right?"]
|
34 |
+
]
|
35 |
+
)
|
36 |
+
|
37 |
+
|
38 |
+
iface.launch()
|