Spaces:
Sleeping
Sleeping
alperugurcan
commited on
Commit
•
012de1c
1
Parent(s):
80edd46
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
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 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
|
|
16 |
demo = gr.Interface(
|
17 |
fn=predict,
|
18 |
-
inputs=[
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
)
|
22 |
|
23 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
|
4 |
+
# Load model
|
5 |
+
model = AutoModelForSequenceClassification.from_pretrained("alperugurcan/Contradictory")
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("alperugurcan/Contradictory")
|
7 |
|
8 |
def predict(premise, hypothesis):
|
9 |
+
# Tokenize and predict
|
10 |
inputs = tokenizer(premise, hypothesis, return_tensors="pt", truncation=True)
|
11 |
outputs = model(**inputs)
|
12 |
prediction = outputs.logits.softmax(-1)[0]
|
13 |
+
|
14 |
+
# Return results
|
15 |
+
return {
|
16 |
+
"Entailment": float(prediction[0]),
|
17 |
+
"Neutral": float(prediction[1]),
|
18 |
+
"Contradiction": float(prediction[2])
|
19 |
+
}
|
20 |
|
21 |
+
# Create interface
|
22 |
demo = gr.Interface(
|
23 |
fn=predict,
|
24 |
+
inputs=[
|
25 |
+
gr.Textbox(label="Premise"),
|
26 |
+
gr.Textbox(label="Hypothesis")
|
27 |
+
],
|
28 |
+
outputs=gr.Label(),
|
29 |
+
title="NLI Classifier",
|
30 |
+
examples=[
|
31 |
+
["The cat is sleeping.", "The cat is awake."],
|
32 |
+
["It's raining.", "The ground is wet."]
|
33 |
+
]
|
34 |
)
|
35 |
|
36 |
demo.launch()
|