Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ def start_haystack():
|
|
17 |
split_length=200,
|
18 |
split_respect_sentence_boundary=True,
|
19 |
)
|
20 |
-
summarizer = TransformersSummarizer(model_name_or_path="
|
21 |
return document_store, summarizer, preprocessor
|
22 |
|
23 |
|
@@ -36,14 +36,26 @@ def summarize(file):
|
|
36 |
pdf_to_document_store(file)
|
37 |
st.write('Number of documents', document_store.get_document_count())
|
38 |
summaries = summarizer.predict(documents=document_store.get_all_documents(), generate_single_summary=True)
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
|
|
|
43 |
document_store, summarizer, preprocessor = start_haystack()
|
44 |
|
45 |
uploaded_file = st.file_uploader("Choose a PDF file", accept_multiple_files=False)
|
46 |
|
47 |
if uploaded_file is not None:
|
48 |
if st.button('Summarize Document'):
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
split_length=200,
|
18 |
split_respect_sentence_boundary=True,
|
19 |
)
|
20 |
+
summarizer = TransformersSummarizer(model_name_or_path="facebook/bart-large-cnn")
|
21 |
return document_store, summarizer, preprocessor
|
22 |
|
23 |
|
|
|
36 |
pdf_to_document_store(file)
|
37 |
st.write('Number of documents', document_store.get_document_count())
|
38 |
summaries = summarizer.predict(documents=document_store.get_all_documents(), generate_single_summary=True)
|
39 |
+
return summaries
|
40 |
+
|
41 |
+
def set_state_if_absent(key, value):
|
42 |
+
if key not in st.session_state:
|
43 |
+
st.session_state[key] = value
|
44 |
|
45 |
+
set_state_if_absent("summaries", None)
|
46 |
document_store, summarizer, preprocessor = start_haystack()
|
47 |
|
48 |
uploaded_file = st.file_uploader("Choose a PDF file", accept_multiple_files=False)
|
49 |
|
50 |
if uploaded_file is not None:
|
51 |
if st.button('Summarize Document'):
|
52 |
+
with st.spinner("📚 Please wait while we produce a summary..."):
|
53 |
+
try:
|
54 |
+
st. session_state.summaries = summarize(uploaded_file)
|
55 |
+
except Exception as e:
|
56 |
+
logging.exception(e)
|
57 |
+
|
58 |
+
if st.session_state.summaries:
|
59 |
+
st.write('## Summary')
|
60 |
+
for count, summary in enumerate(st.session_state.summaries):
|
61 |
+
st.write(summary.content)
|