com3dian commited on
Commit
39f102c
·
verified ·
1 Parent(s): 181cf6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -39
app.py CHANGED
@@ -29,52 +29,48 @@ st.title('Paper2Slides')
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
- # outline = monkeyReader.readOutline(saved_file_path)
49
- # for pre, fill, node in outline:
50
- # st.write("%s%s" % (pre, node.name))
51
 
 
 
52
 
53
- # # read paper content
54
- # essay = monkeyReader.readEssay(saved_file_path)
55
 
56
- # with st.status("Understanding paper..."):
57
 
58
- # Barttokenizer = BartTokenizer.from_pretrained('facebook/bart-large-cnn')
59
- # summ_model_path = 'com3dian/Bart-large-paper2slides-summarizer'
60
- # summarizor = BartForConditionalGeneration.from_pretrained(summ_model_path)
61
- # exp_model_path = 'com3dian/Bart-large-paper2slides-expander'
62
- # expandor = BartForConditionalGeneration.from_pretrained(exp_model_path)
63
- # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
64
- # BartSE = BARTAutoEncoder(summarizor, summarizor, device)
65
- # del summarizor, expandor
66
 
67
- # document = Document(essay, Barttokenizer)
68
- # del Barttokenizer
69
- # length = document.merge(25, 30, BartSE, device)
70
-
71
- # with st.status("Generating slides..."):
72
- # summarizor = pipeline("summarization", model=summ_model_path, device = device)
73
- # summ_text = summarizor(document.segmentation['text'], max_length=100, min_length=10, do_sample=False)
74
- # summ_text = [text['summary_text'] for text in summ_text]
75
 
76
- # for summ in summ_text:
77
- # st.write(summ)
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: