Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,9 @@ import PyPDF2
|
|
3 |
from PIL import Image
|
4 |
import streamlit as st
|
5 |
|
|
|
|
|
|
|
6 |
def read_pdf(pdf):
|
7 |
reader=PyPDF2.PdfReader(pdf)
|
8 |
text=''
|
@@ -15,9 +18,10 @@ def read_pdf(pdf):
|
|
15 |
return text
|
16 |
|
17 |
|
18 |
-
def summarizer(
|
19 |
-
model = T5ForConditionalGeneration.from_pretrained("t5-base")
|
20 |
-
tokenizer = T5TokenizerFast.from_pretrained("t5-base")
|
|
|
21 |
inputs = tokenizer.encode("summarize: " + text,return_tensors="pt", max_length=1000,truncation=True)
|
22 |
outputs = model.generate(inputs,max_length=1000, min_length=100,length_penalty=2.0, num_beams=4,early_stopping=True)
|
23 |
summary = tokenizer.decode(outputs[0])
|
@@ -31,11 +35,8 @@ uploaded_file = st.file_uploader('Choose your .pdf file', type="pdf")
|
|
31 |
if uploaded_file is not None:
|
32 |
if st.button('Summarize Document'):
|
33 |
with st.spinner("π Please wait while we produce a summary..."):
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
st.divider()
|
40 |
-
except Exception as e:
|
41 |
-
pass
|
|
|
3 |
from PIL import Image
|
4 |
import streamlit as st
|
5 |
|
6 |
+
model = T5ForConditionalGeneration.from_pretrained("t5-base")
|
7 |
+
tokenizer = T5TokenizerFast.from_pretrained("t5-base")
|
8 |
+
|
9 |
def read_pdf(pdf):
|
10 |
reader=PyPDF2.PdfReader(pdf)
|
11 |
text=''
|
|
|
18 |
return text
|
19 |
|
20 |
|
21 |
+
def summarizer(pdf):
|
22 |
+
# model = T5ForConditionalGeneration.from_pretrained("t5-base")
|
23 |
+
# tokenizer = T5TokenizerFast.from_pretrained("t5-base")
|
24 |
+
text=read_pdf(pdf)
|
25 |
inputs = tokenizer.encode("summarize: " + text,return_tensors="pt", max_length=1000,truncation=True)
|
26 |
outputs = model.generate(inputs,max_length=1000, min_length=100,length_penalty=2.0, num_beams=4,early_stopping=True)
|
27 |
summary = tokenizer.decode(outputs[0])
|
|
|
35 |
if uploaded_file is not None:
|
36 |
if st.button('Summarize Document'):
|
37 |
with st.spinner("π Please wait while we produce a summary..."):
|
38 |
+
# text=read_pdf(uploaded_file)
|
39 |
+
summary=summarizer(uploaded_file)
|
40 |
+
st.divider()
|
41 |
+
st.markdown(summary, unsafe_allow_html=True)
|
42 |
+
st.divider()
|
|
|
|
|
|