Commit
Β·
9a6d2b3
1
Parent(s):
c85d7fb
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ nltk.download('stopwords')
|
|
13 |
# Function to read and preprocess the article
|
14 |
def read_article(article):
|
15 |
sentences = nltk.sent_tokenize(article)
|
16 |
-
sentences = [sentence for sentence in sentences if len
|
17 |
return sentences
|
18 |
|
19 |
# Function to compute sentence similarity based on cosine similarity
|
@@ -43,7 +43,7 @@ def sentence_similarity(sent1, sent2, stopwords):
|
|
43 |
|
44 |
# Function to create a similarity matrix of sentences
|
45 |
def build_similarity_matrix(sentences, stopwords):
|
46 |
-
similarity_matrix = np.zeros((len(sentences), len(sentences))
|
47 |
|
48 |
for i in range(len(sentences)):
|
49 |
for j in range(len(sentences)):
|
@@ -72,11 +72,11 @@ def generate_summary(article, top_n=5):
|
|
72 |
summary = " ".join([sentence for _, sentence in ranked_sentences[:top_n]])
|
73 |
return summary
|
74 |
|
75 |
-
# Streamlit web app with improved styling
|
76 |
-
st.set_page_config(page_title="Article Summarizer", page_icon="
|
77 |
st.title("Article Summarizer")
|
78 |
|
79 |
-
# Custom CSS to style the app
|
80 |
st.markdown(
|
81 |
"""
|
82 |
<style>
|
@@ -98,31 +98,31 @@ st.markdown(
|
|
98 |
unsafe_allow_html=True,
|
99 |
)
|
100 |
|
101 |
-
user_article = st.text_area("Enter your article here:", height=200)
|
102 |
-
translate = st.checkbox("Translate Summary")
|
103 |
|
104 |
if translate:
|
105 |
-
target_language = st.selectbox("Select Target Language", ["English", "French", "Spanish", "German"])
|
106 |
|
107 |
if st.button("Summarize"):
|
108 |
if user_article:
|
109 |
summary = generate_summary(user_article)
|
110 |
-
st.subheader("Summary:")
|
111 |
st.write(summary)
|
112 |
|
113 |
if translate:
|
114 |
-
if target_language == "English":
|
115 |
target_language_code = "en"
|
116 |
-
elif target_language == "French":
|
117 |
target_language_code = "fr"
|
118 |
-
elif target_language == "Spanish":
|
119 |
target_language_code = "es"
|
120 |
-
elif target_language == "German":
|
121 |
target_language_code = "de"
|
122 |
|
123 |
translator = Translator()
|
124 |
translated_summary = translator.translate(summary, dest=target_language_code)
|
125 |
-
st.subheader("Translated Summary:")
|
126 |
st.write(translated_summary.text)
|
127 |
else:
|
128 |
-
st.warning("Please enter an article to summarize.")
|
|
|
13 |
# Function to read and preprocess the article
|
14 |
def read_article(article):
|
15 |
sentences = nltk.sent_tokenize(article)
|
16 |
+
sentences = [sentence for sentence in sentences if len sentence > 10] # Filter out very short sentences
|
17 |
return sentences
|
18 |
|
19 |
# Function to compute sentence similarity based on cosine similarity
|
|
|
43 |
|
44 |
# Function to create a similarity matrix of sentences
|
45 |
def build_similarity_matrix(sentences, stopwords):
|
46 |
+
similarity_matrix = np.zeros((len(sentences), len(sentences))
|
47 |
|
48 |
for i in range(len(sentences)):
|
49 |
for j in range(len(sentences)):
|
|
|
72 |
summary = " ".join([sentence for _, sentence in ranked_sentences[:top_n]])
|
73 |
return summary
|
74 |
|
75 |
+
# Streamlit web app with improved styling and icons
|
76 |
+
st.set_page_config(page_title="Article Summarizer", page_icon="βοΈ")
|
77 |
st.title("Article Summarizer")
|
78 |
|
79 |
+
# Custom CSS to style the app with icons
|
80 |
st.markdown(
|
81 |
"""
|
82 |
<style>
|
|
|
98 |
unsafe_allow_html=True,
|
99 |
)
|
100 |
|
101 |
+
user_article = st.text_area("βοΈ Enter your article here:", height=200)
|
102 |
+
translate = st.checkbox("π Translate Summary")
|
103 |
|
104 |
if translate:
|
105 |
+
target_language = st.selectbox("π Select Target Language", ["πΊπΈ English", "π«π· French", "πͺπΈ Spanish", "π©πͺ German"])
|
106 |
|
107 |
if st.button("Summarize"):
|
108 |
if user_article:
|
109 |
summary = generate_summary(user_article)
|
110 |
+
st.subheader("π Summary:")
|
111 |
st.write(summary)
|
112 |
|
113 |
if translate:
|
114 |
+
if target_language == "πΊπΈ English":
|
115 |
target_language_code = "en"
|
116 |
+
elif target_language == "π«π· French":
|
117 |
target_language_code = "fr"
|
118 |
+
elif target_language == "πͺπΈ Spanish":
|
119 |
target_language_code = "es"
|
120 |
+
elif target_language == "π©πͺ German":
|
121 |
target_language_code = "de"
|
122 |
|
123 |
translator = Translator()
|
124 |
translated_summary = translator.translate(summary, dest=target_language_code)
|
125 |
+
st.subheader("π Translated Summary:")
|
126 |
st.write(translated_summary.text)
|
127 |
else:
|
128 |
+
st.warning("π« Please enter an article to summarize.")
|