BenTouss commited on
Commit
8329fd1
·
verified ·
1 Parent(s): b903e14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -1,7 +1,31 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ # Load model and tokenizer
6
+ tokenizer = AutoTokenizer.from_pretrained("BenTouss/mdeberta-eurochef")
7
+ model = AutoModelForSequenceClassification.from_pretrained("BenTouss/mdeberta-eurochef")
8
+
9
+ def get_labels(text):
10
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
11
+
12
+ # Get predictions
13
+ with torch.no_grad():
14
+ outputs = model(**inputs)
15
+ probs = torch.sigmoid(outputs.logits)[0]
16
+
17
+ # Get predicted labels (threshold = 0.6)
18
+ predicted_labels = []
19
+ for idx, prob in enumerate(probs):
20
+ if prob > 0.6:
21
+ label = model.config.id2label[idx]
22
+ predicted_labels.append((label, prob.item()))
23
+
24
+ return predicted_labels
25
+
26
 
27
  def greet(name):
28
  return "Hello " + name + "!!"
29
 
30
+ demo = gr.Interface(fn=get_labels, inputs="text", outputs="text")
31
  demo.launch()