File size: 2,237 Bytes
4e92053
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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")


def init_session_state():
    if 'history' not in st.session_state:
        st.session_state.history = ""

# Initialize session state
init_session_state()
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
# 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, labels, 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)

    output = output["labels"][0]

    labels = list(dictionary[output])

    output2 = classify(text,labels)

    output2 = output2["labels"][0]


    answer = dictionary[output][output2]


    st.session_state.history += "Based on the following information" + answer +"answer this question:" + text  # Add new text to history
    out = pipe(st.session_state.history)  # Generate output based on history
    st.text(out[0]['generated_text'])
    # st.text("History: " + st.session_state.history)

    # st.text(output)
    # st.text(output2)

    # st.text(answer)