Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,52 +29,48 @@ st.title('Paper2Slides')
|
|
29 |
|
30 |
st.subheader('Upload paper in pdf format')
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# st.write(uploaded_file.name)
|
43 |
-
# bytes_data = uploaded_file.getvalue()
|
44 |
-
# st.write(len(bytes_data), "bytes")
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
# for pre, fill, node in outline:
|
50 |
-
# st.write("%s%s" % (pre, node.name))
|
51 |
|
|
|
|
|
52 |
|
53 |
-
#
|
54 |
-
|
55 |
|
56 |
-
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
|
76 |
-
|
77 |
-
|
78 |
|
79 |
|
80 |
with open('slides_text.pkl', 'rb') as file:
|
|
|
29 |
|
30 |
st.subheader('Upload paper in pdf format')
|
31 |
|
32 |
+
col1, col2 = st.columns([3, 1])
|
33 |
+
with col1:
|
34 |
+
uploaded_file = st.file_uploader("Choose a file")
|
35 |
+
with col2:
|
36 |
+
option = st.selectbox(
|
37 |
+
'Select parsing method.',
|
38 |
+
('monkey', 'x2d', 'lxml'))
|
39 |
+
|
40 |
+
if uploaded_file is not None:
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
st.write(uploaded_file.name)
|
43 |
+
bytes_data = uploaded_file.getvalue()
|
44 |
+
st.write(len(bytes_data), "bytes")
|
|
|
|
|
45 |
|
46 |
+
saved_file_path = save_uploaded_file(uploaded_file)
|
47 |
+
monkeyReader = reader.MonkeyReader(option)
|
48 |
|
49 |
+
# read paper content
|
50 |
+
essay = monkeyReader.readEssay(saved_file_path)
|
51 |
|
52 |
+
with st.status("Understanding paper..."):
|
53 |
|
54 |
+
Barttokenizer = BartTokenizer.from_pretrained('facebook/bart-large-cnn')
|
55 |
+
summ_model_path = 'com3dian/Bart-large-paper2slides-summarizer'
|
56 |
+
summarizor = BartForConditionalGeneration.from_pretrained(summ_model_path)
|
57 |
+
exp_model_path = 'com3dian/Bart-large-paper2slides-expander'
|
58 |
+
expandor = BartForConditionalGeneration.from_pretrained(exp_model_path)
|
59 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
60 |
+
BartSE = BARTAutoEncoder(summarizor, summarizor, device)
|
61 |
+
del summarizor, expandor
|
62 |
|
63 |
+
document = Document(essay, Barttokenizer)
|
64 |
+
del Barttokenizer
|
65 |
+
length = document.merge(25, 30, BartSE, device)
|
66 |
+
|
67 |
+
with st.status("Generating slides..."):
|
68 |
+
summarizor = pipeline("summarization", model=summ_model_path, device = device)
|
69 |
+
summ_text = summarizor(document.segmentation['text'], max_length=100, min_length=10, do_sample=False)
|
70 |
+
summ_text = [text['summary_text'] for text in summ_text]
|
71 |
|
72 |
+
for summ in summ_text:
|
73 |
+
st.write(summ)
|
74 |
|
75 |
|
76 |
with open('slides_text.pkl', 'rb') as file:
|