Towhidul commited on
Commit
e108d52
1 Parent(s): c92a93e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # List of sentences
4
+ sentence1 = [f"U.S. President Barack Obama declared that the U.S. will refrain from deploying troops in Ukraine."]
5
+ sentence2 = [f"Joe Biden said we’d not send U.S. troops to fight Russian troops in Ukraine, but we would provide robust military assistance and try to unify the Western world against Russia’s aggression."]
6
+ # Create a dropdown menu
7
+ selected_sentence1 = st.selectbox("Select first sentence:", sentence1)
8
+ selected_sentence2 = st.selectbox("Select first sentence:", sentence2)
9
+
10
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
11
+ import torch
12
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
13
+
14
+ model_name = "MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7"
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
17
+
18
+
19
+ premise = sentence1
20
+ hypothesis = sentence2
21
+ input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
22
+ output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
23
+ prediction = torch.softmax(output["logits"][0], -1).tolist()
24
+ label_names = ["support", "neutral", "refute"]
25
+ prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
26
+ print(prediction)
27
+
28
+ st.write("Result:", prediction)