Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
2 |
+
import torch
|
3 |
+
import pickle
|
4 |
+
import streamlit as st
|
5 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
6 |
+
|
7 |
+
|
8 |
+
def init_session_state():
|
9 |
+
if 'history' not in st.session_state:
|
10 |
+
st.session_state.history = ""
|
11 |
+
|
12 |
+
# Initialize session state
|
13 |
+
init_session_state()
|
14 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
|
15 |
+
# model_name = "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
|
16 |
+
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
17 |
+
# model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
18 |
+
|
19 |
+
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli")
|
20 |
+
|
21 |
+
# with open('chapter_titles.pkl', 'rb') as file:
|
22 |
+
# titles_astiko = pickle.load(file)
|
23 |
+
# labels1 = ["κληρονομικό", "ακίνητα", "διαζύγιο"]
|
24 |
+
# # labels2 = ["αποδοχή κληρονομιάς", "αποποίηση", "διαθήκη"]
|
25 |
+
# # labels3 = ["μίσθωση", "κυριότητα", "έξωση", "απλήρωτα νοίκια"]
|
26 |
+
|
27 |
+
|
28 |
+
# titles_astiko = ["γάμος", "αλλοδαπός", "φορολογία", "κληρονομικά", "στέγη", "οικογενειακό", "εμπορικό","κλοπή","απάτη"]
|
29 |
+
# Load dictionary from the file using pickle
|
30 |
+
with open('my_dict.pickle', 'rb') as file:
|
31 |
+
dictionary = pickle.load(file)
|
32 |
+
|
33 |
+
def classify(text,labels):
|
34 |
+
output = classifier(text, labels, multi_label=False)
|
35 |
+
|
36 |
+
return output
|
37 |
+
|
38 |
+
|
39 |
+
text = st.text_input('Enter some text:') # Input field for new text
|
40 |
+
|
41 |
+
if text:
|
42 |
+
|
43 |
+
labels = list(dictionary)
|
44 |
+
|
45 |
+
output = classify(text,labels)
|
46 |
+
|
47 |
+
output = output["labels"][0]
|
48 |
+
|
49 |
+
labels = list(dictionary[output])
|
50 |
+
|
51 |
+
output2 = classify(text,labels)
|
52 |
+
|
53 |
+
output2 = output2["labels"][0]
|
54 |
+
|
55 |
+
|
56 |
+
answer = dictionary[output][output2]
|
57 |
+
|
58 |
+
|
59 |
+
st.session_state.history += "Based on the following information" + answer +"answer this question:" + text # Add new text to history
|
60 |
+
out = pipe(st.session_state.history) # Generate output based on history
|
61 |
+
st.text(out[0]['generated_text'])
|
62 |
+
# st.text("History: " + st.session_state.history)
|
63 |
+
|
64 |
+
# st.text(output)
|
65 |
+
# st.text(output2)
|
66 |
+
|
67 |
+
# st.text(answer)
|