Ismetdh commited on
Commit
43fbc78
·
verified ·
1 Parent(s): a541e13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -41
app.py CHANGED
@@ -1,41 +1,41 @@
1
- import streamlit as st
2
- import re
3
- import nltk
4
- nltk.download('punkt') # Ensure sentence tokenizers are available.
5
- # Import your summarizer. Replace these paths with your actual model and tokenizer paths.
6
- from summarizer import Summarizer
7
-
8
- def clean_text(text):
9
- """
10
- Cleans the text by removing extra whitespace.
11
- You can expand this function to include additional cleaning as needed.
12
- """
13
- cleaned = re.sub(r'\s+', ' ', text).strip()
14
- return cleaned
15
-
16
- # Initialize your summarizer. Make sure to set the correct paths.
17
- MODEL_PATH = r"server_side_summarize_news" # Replace with your model path.
18
- TOKENIZER_PATH = r"server_side_summarize_news" # Replace with your tokenizer path.
19
- summarizer = Summarizer(MODEL_PATH, TOKENIZER_PATH)
20
-
21
- # Set up the Streamlit UI.
22
- st.title("Text Summarizer")
23
- st.write("Enter your text below to generate a summary:")
24
-
25
- # Text area for user input.
26
- input_text = st.text_area("Input Text", height=200)
27
-
28
- # When the 'Summarize' button is pressed, process the input.
29
- if st.button("Summarize"):
30
- if not input_text.strip():
31
- st.warning("Please enter some text to summarize.")
32
- else:
33
- # Clean the input text.
34
- cleaned_text = clean_text(input_text)
35
- try:
36
- # Generate the summary using your summarizer.
37
- summary = summarizer.iterative_summarization(cleaned_text)
38
- st.subheader("Summary")
39
- st.write(summary)
40
- except Exception as e:
41
- st.error(f"An error occurred during summarization: {e}")
 
1
+ import streamlit as st
2
+ import re
3
+ import nltk
4
+ nltk.download('punkt_tab') # Ensure sentence tokenizers are available.
5
+ # Import your summarizer. Replace these paths with your actual model and tokenizer paths.
6
+ from summarizer import Summarizer
7
+
8
+ def clean_text(text):
9
+ """
10
+ Cleans the text by removing extra whitespace.
11
+ You can expand this function to include additional cleaning as needed.
12
+ """
13
+ cleaned = re.sub(r'\s+', ' ', text).strip()
14
+ return cleaned
15
+
16
+ # Initialize your summarizer. Make sure to set the correct paths.
17
+ MODEL_PATH = r"server_side_summarize_news" # Replace with your model path.
18
+ TOKENIZER_PATH = r"server_side_summarize_news" # Replace with your tokenizer path.
19
+ summarizer = Summarizer(MODEL_PATH, TOKENIZER_PATH)
20
+
21
+ # Set up the Streamlit UI.
22
+ st.title("Text Summarizer")
23
+ st.write("Enter your text below to generate a summary:")
24
+
25
+ # Text area for user input.
26
+ input_text = st.text_area("Input Text", height=200)
27
+
28
+ # When the 'Summarize' button is pressed, process the input.
29
+ if st.button("Summarize"):
30
+ if not input_text.strip():
31
+ st.warning("Please enter some text to summarize.")
32
+ else:
33
+ # Clean the input text.
34
+ cleaned_text = clean_text(input_text)
35
+ try:
36
+ # Generate the summary using your summarizer.
37
+ summary = summarizer.iterative_summarization(cleaned_text)
38
+ st.subheader("Summary")
39
+ st.write(summary)
40
+ except Exception as e:
41
+ st.error(f"An error occurred during summarization: {e}")