alperugurcan commited on
Commit
dfd48e1
1 Parent(s): 6d45fcb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ model_name = "your-username/nli-mdeberta-model"
5
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
+
8
+ def predict(premise, hypothesis):
9
+ inputs = tokenizer(premise, hypothesis, return_tensors="pt", truncation=True)
10
+ outputs = model(**inputs)
11
+ prediction = outputs.logits.softmax(-1)[0]
12
+ return {"Entailment": prediction[0].item(),
13
+ "Neutral": prediction[1].item(),
14
+ "Contradiction": prediction[2].item()}
15
+
16
+ demo = gr.Interface(
17
+ fn=predict,
18
+ inputs=["text", "text"],
19
+ outputs="label",
20
+ title="NLI Classifier"
21
+ )
22
+
23
+ demo.launch()