WAQASCHANNA commited on
Commit
1fff357
·
verified ·
1 Parent(s): a9d4fb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -15,21 +15,26 @@ do_sample = st.sidebar.checkbox("Use Sampling", value=False)
15
 
16
  # Main area - Display content and summary
17
  if uploaded_file is not None:
18
- text = uploaded_file.read().decode("utf-8")
19
-
20
- # Ensure the text is long enough
21
- if len(text.split()) > min_length:
22
- try:
 
23
  # Load the model from Hugging Face
24
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
25
-
26
  # Summarize the document
27
  summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=do_sample)
28
  st.subheader("Summary:")
29
  st.write(summary[0]['summary_text'])
30
- except Exception as e:
31
- st.error(f"An error occurred: {e}")
32
- else:
33
- st.warning("Text is too short to summarize.")
 
 
 
 
34
  else:
35
  st.info("Please upload a document to summarize.")
 
15
 
16
  # Main area - Display content and summary
17
  if uploaded_file is not None:
18
+ try:
19
+ # Read the uploaded file and decode it
20
+ text = uploaded_file.read().decode("utf-8")
21
+
22
+ # Ensure the text is long enough for summarization
23
+ if len(text.split()) > min_length:
24
  # Load the model from Hugging Face
25
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
26
+
27
  # Summarize the document
28
  summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=do_sample)
29
  st.subheader("Summary:")
30
  st.write(summary[0]['summary_text'])
31
+ else:
32
+ st.warning("The document is too short to summarize. Please upload a longer document.")
33
+
34
+ except IndexError as e:
35
+ st.error(f"IndexError: {e}. This error may occur if the text is too short or there's an issue with the model's processing. Try adjusting the summarization parameters or uploading a longer document.")
36
+
37
+ except Exception as e:
38
+ st.error(f"An unexpected error occurred: {e}")
39
  else:
40
  st.info("Please upload a document to summarize.")