aps19 commited on
Commit
1fb96d0
1 Parent(s): aac59e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -4,12 +4,12 @@ from transformers import T5Tokenizer, T5ForConditionalGeneration
4
  from transformers import pipeline
5
 
6
  # Model and tokenizer loading
7
- checkpoint = "./model/LaMini-Flan-T5-248M"
8
  tokenizer = T5Tokenizer.from_pretrained(checkpoint)
9
  base_model = T5ForConditionalGeneration.from_pretrained(checkpoint)
10
 
11
  # LLM pipeline
12
- def llm_pipeline(pdf_contents):
13
  # Extract text from the PDF contents
14
  pdf_document = fitz.open(stream=pdf_contents, filetype="pdf")
15
  pdf_text = ""
@@ -22,8 +22,8 @@ def llm_pipeline(pdf_contents):
22
  'summarization',
23
  model=base_model,
24
  tokenizer=tokenizer,
25
- max_length=500,
26
- min_length=50
27
  )
28
 
29
  result = pipe_sum(pdf_text)
@@ -40,10 +40,13 @@ def main():
40
  uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
41
 
42
  if uploaded_file is not None:
 
 
 
43
  if st.button("Summarize"):
44
  # Check if the uploaded file is a PDF
45
  if uploaded_file.type == "application/pdf":
46
- summary = llm_pipeline(uploaded_file.read())
47
 
48
  # Display the summary
49
  st.info("Summarization Complete")
 
4
  from transformers import pipeline
5
 
6
  # Model and tokenizer loading
7
+ checkpoint = "./model/LaMini-Flan-T5-248M"
8
  tokenizer = T5Tokenizer.from_pretrained(checkpoint)
9
  base_model = T5ForConditionalGeneration.from_pretrained(checkpoint)
10
 
11
  # LLM pipeline
12
+ def llm_pipeline(pdf_contents, max_length=500, min_length=50):
13
  # Extract text from the PDF contents
14
  pdf_document = fitz.open(stream=pdf_contents, filetype="pdf")
15
  pdf_text = ""
 
22
  'summarization',
23
  model=base_model,
24
  tokenizer=tokenizer,
25
+ max_length=max_length,
26
+ min_length=min_length
27
  )
28
 
29
  result = pipe_sum(pdf_text)
 
40
  uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
41
 
42
  if uploaded_file is not None:
43
+ max_length = st.slider("Maximum Summary Length", min_value=50, max_value=1000, step=50, value=500)
44
+ min_length = st.slider("Minimum Summary Length", min_value=10, max_value=500, step=10, value=50)
45
+
46
  if st.button("Summarize"):
47
  # Check if the uploaded file is a PDF
48
  if uploaded_file.type == "application/pdf":
49
+ summary = llm_pipeline(uploaded_file.read(), max_length, min_length)
50
 
51
  # Display the summary
52
  st.info("Summarization Complete")