patrickott1 commited on
Commit
d77aa9e
·
verified ·
1 Parent(s): 7f647f0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ MODEL_NAME = "ton-username/ton-modele"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
9
+
10
+ def predict(text):
11
+ inputs = tokenizer(text, return_tensors="pt", truncation=True)
12
+ outputs = model(**inputs)
13
+ probs = torch.nn.functional.softmax(outputs.logits, dim=1)
14
+ predicted_class = torch.argmax(probs).item()
15
+ confidence = probs[0][predicted_class].item()
16
+
17
+ return f"Classe: {predicted_class} (confiance: {confidence:.2f})"
18
+
19
+ interface = gr.Interface(
20
+ fn=predict,
21
+ inputs="text",
22
+ outputs="text",
23
+ title="Mon modèle de classification",
24
+ description="Entrez un texte pour prédiction."
25
+ )
26
+
27
+ interface.launch()