File size: 1,587 Bytes
12ba4ff 52f43c9 0dc3afb 52f43c9 805f6fe bb86df1 9cf8085 17ebaff 46cd5e7 b93d861 9cf8085 46cd5e7 9cf8085 bb86df1 f526817 9cf8085 52f43c9 9cf8085 52f43c9 9cf8085 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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")
# model_name = "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
# tokenizer = AutoTokenizer.from_pretrained(model_name)
# model = AutoModelForSequenceClassification.from_pretrained(model_name)
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli")
# with open('chapter_titles.pkl', 'rb') as file:
# titles_astiko = pickle.load(file)
# labels1 = ["κληρονομικό", "ακίνητα", "διαζύγιο"]
# labels2 = ["αποδοχή κληρονομιάς", "αποποίηση", "διαθήκη"]
# labels3 = ["μίσθωση", "κυριότητα", "έξωση", "απλήρωτα νοίκια"]
# titles_astiko = ["γάμος", "αλλοδαπός", "φορολογία", "κληρονομικά", "στέγη", "οικογενειακό", "εμπορικό","κλοπή","απάτη"]
# Load dictionary from the file using pickle
with open('my_dict.pickle', 'rb') as file:
dictionary = pickle.load(file)
def classify(text,labels):
output = classifier(text, labels1, multi_label=False)
return output
text = st.text_input('Enter some text:') # Input field for new text
if text:
labels = list(dictionary)
output = classify(text,labels)
labels = list(dictionary[output])
output2 = classify(text,labels)
answer = dictionary[output][output2]
st.text(answer)
|