|
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline |
|
import torch |
|
import pickle |
|
import streamlit as st |
|
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") |
|
|
|
|
|
|
|
|
|
|
|
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open('my_dict.pickle', 'rb') as file: |
|
dictionary = pickle.load(file) |
|
|
|
def classify(text,labels): |
|
output = classifier(text, labels, multi_label=False) |
|
|
|
return output |
|
|
|
|
|
text = st.text_input('Enter some text:') |
|
|
|
if text: |
|
|
|
labels = list(dictionary) |
|
|
|
output = classify(text,labels) |
|
|
|
output = output["labels"][0] |
|
|
|
labels = list(dictionary[output]) |
|
|
|
output2 = classify(text,labels) |
|
|
|
output2 = output2["labels"][0] |
|
|
|
|
|
answer = dictionary[output][output2] |
|
|
|
st.text(output) |
|
st.text(output2) |
|
|
|
st.text(answer) |
|
|
|
|
|
|
|
|