nurindahpratiwi commited on
Commit
6ca90ab
1 Parent(s): 159ae14
Files changed (1) hide show
  1. app.py +7 -18
app.py CHANGED
@@ -26,12 +26,12 @@ def preprocess_pdf(file):
26
  return final_text
27
 
28
  # Language Model pipeline
29
- def language_model_pipeline(filepath, maxlength):
30
  summarization_pipeline = pipeline(
31
  'summarization',
32
  model=model,
33
  tokenizer=model_tokenizer,
34
- max_length=maxlength,
35
  min_length=32)
36
  input_text = preprocess_pdf(filepath)
37
  summary_result = summarization_pipeline(input_text)
@@ -40,31 +40,20 @@ def language_model_pipeline(filepath, maxlength):
40
 
41
  @st.cache_data
42
  # Function to display the PDF content
43
- def display_pdf(file):
44
- with open(file, "rb") as f:
45
- base64_pdf = base64.b64encode(f.read()).decode('utf-8')
46
-
47
- pdf_display = f'<object data="data:application/pdf;base64,{base64_pdf}" width="100%" height="600" type="application/pdf"></object>'
48
- st.markdown(pdf_display, unsafe_allow_html=True)
49
 
50
  def main():
51
  st.title("PDF Summarization App using Language Model")
52
  uploaded_file = st.file_uploader("Upload your PDF file", type=['pdf'])
53
- maxlength = st.slider(label="Token Length", min_value=32, max_value=1024, step=32, value=1024)
54
-
55
  if uploaded_file is not None:
56
  if st.button("Summarize"):
57
- col1, col2 = st.columns(2)
58
  filepath = uploaded_file.name
59
  with open(filepath, "wb") as temp_file:
60
  temp_file.write(uploaded_file.read())
61
- with col1:
62
- st.success("File Uploaded")
63
-
64
- with col2:
65
- summarized_result = language_model_pipeline(filepath, maxlength)
66
- st.info("Summarization Complete")
67
- st.success(summarized_result)
68
 
69
  if __name__ == "__main__":
70
  main()
 
26
  return final_text
27
 
28
  # Language Model pipeline
29
+ def language_model_pipeline(filepath):
30
  summarization_pipeline = pipeline(
31
  'summarization',
32
  model=model,
33
  tokenizer=model_tokenizer,
34
+ max_length=500,
35
  min_length=32)
36
  input_text = preprocess_pdf(filepath)
37
  summary_result = summarization_pipeline(input_text)
 
40
 
41
  @st.cache_data
42
  # Function to display the PDF content
 
 
 
 
 
 
43
 
44
  def main():
45
  st.title("PDF Summarization App using Language Model")
46
  uploaded_file = st.file_uploader("Upload your PDF file", type=['pdf'])
47
+ st.success("File Uploaded")
 
48
  if uploaded_file is not None:
49
  if st.button("Summarize"):
 
50
  filepath = uploaded_file.name
51
  with open(filepath, "wb") as temp_file:
52
  temp_file.write(uploaded_file.read())
53
+
54
+ summarized_result = language_model_pipeline(filepath)
55
+ st.info("Summarization Complete")
56
+ st.success(summarized_result)
 
 
 
57
 
58
  if __name__ == "__main__":
59
  main()