alperugurcan commited on
Commit
42afca8
·
verified ·
1 Parent(s): 012de1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -1,24 +1,22 @@
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=[
@@ -26,7 +24,7 @@ demo = gr.Interface(
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."]
 
1
  import gradio as gr
2
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
 
5
  # Load model
6
+ model = AutoModelForSequenceClassification.from_pretrained("nli_model")
7
+ tokenizer = AutoTokenizer.from_pretrained("nli_model")
8
 
9
  def predict(premise, hypothesis):
 
10
  inputs = tokenizer(premise, hypothesis, return_tensors="pt", truncation=True)
11
  outputs = model(**inputs)
12
  prediction = outputs.logits.softmax(-1)[0]
13
 
 
14
  return {
15
  "Entailment": float(prediction[0]),
16
  "Neutral": float(prediction[1]),
17
  "Contradiction": float(prediction[2])
18
  }
19
 
 
20
  demo = gr.Interface(
21
  fn=predict,
22
  inputs=[
 
24
  gr.Textbox(label="Hypothesis")
25
  ],
26
  outputs=gr.Label(),
27
+ title="Natural Language Inference",
28
  examples=[
29
  ["The cat is sleeping.", "The cat is awake."],
30
  ["It's raining.", "The ground is wet."]