MrPio commited on
Commit
4ffcee4
·
verified ·
1 Parent(s): 5c4b8ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -7,7 +7,7 @@ CLASSES = {
7
  'irrelevant': 1,
8
  'no': 2,
9
  }
10
- tokenizer = DebertaV2Tokenizer.from_pretrained('cross-encoder/nli-deberta-v3-base',do_lower_case=True)
11
  model = AutoModelForSequenceClassification.from_pretrained('MrPio/TheSeagullStory-nli-deberta-v3-base')
12
  model.eval()
13
  story = open('story.txt').read().replace("\n\n", "\n").replace("\n", " ").strip()
@@ -15,11 +15,11 @@ story = open('story.txt').read().replace("\n\n", "\n").replace("\n", " ").strip(
15
 
16
  def ask(question):
17
  inputs = tokenizer(story, question, truncation=True, padding=True)
18
- prediction = torch.round(torch.softmax(model(**inputs).logits, 1).squeeze().numpy(), 3)
19
- return {c: prediction[i].item() for c, i in CLASSES}
20
 
21
 
22
- demo = gr.Interface(
23
  ask,
24
  inputs=[gr.Textbox(value="", label="Your question, as an affirmative sentence:")],
25
  outputs=[gr.Label(label="Answer", num_top_classes=3)],
@@ -35,4 +35,4 @@ demo = gr.Interface(
35
  )
36
 
37
  if __name__ == "__main__":
38
- demo.launch()
 
7
  'irrelevant': 1,
8
  'no': 2,
9
  }
10
+ tokenizer = DebertaV2Tokenizer.from_pretrained('cross-encoder/nli-deberta-v3-base', do_lower_case=True)
11
  model = AutoModelForSequenceClassification.from_pretrained('MrPio/TheSeagullStory-nli-deberta-v3-base')
12
  model.eval()
13
  story = open('story.txt').read().replace("\n\n", "\n").replace("\n", " ").strip()
 
15
 
16
  def ask(question):
17
  inputs = tokenizer(story, question, truncation=True, padding=True)
18
+ prediction = torch.softmax(model(**inputs).logits, 1).squeeze()
19
+ return {c: round(prediction[i].item(), 3) for c, i in CLASSES}
20
 
21
 
22
+ gradio = gr.Interface(
23
  ask,
24
  inputs=[gr.Textbox(value="", label="Your question, as an affirmative sentence:")],
25
  outputs=[gr.Label(label="Answer", num_top_classes=3)],
 
35
  )
36
 
37
  if __name__ == "__main__":
38
+ gradio.launch(share=True)