Commit
·
4a3dc04
1
Parent(s):
e30b015
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ def read_article(article):
|
|
19 |
# Function to compute sentence similarity based on cosine similarity
|
20 |
def sentence_similarity(sent1, sent2, stopwords):
|
21 |
words1 = nltk.word_tokenize(sent1)
|
22 |
-
words2 = nltk.word_tokenize
|
23 |
|
24 |
words1 = [word.lower() for word in words1 if word.isalnum()]
|
25 |
words2 = [word.lower() for word in words2 if word.isalnum()]
|
@@ -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)):
|
@@ -76,6 +76,7 @@ def generate_summary(article, top_n=5):
|
|
76 |
st.title("Article Summarizer")
|
77 |
user_article = st.text_area("Enter your article here:")
|
78 |
translate = st.checkbox("Translate Summary")
|
|
|
79 |
|
80 |
if st.button("Summarize"):
|
81 |
if user_article:
|
@@ -84,14 +85,18 @@ if st.button("Summarize"):
|
|
84 |
st.write(summary)
|
85 |
|
86 |
if translate:
|
87 |
-
target_language
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
else:
|
97 |
st.warning("Please enter an article to summarize.")
|
|
|
19 |
# Function to compute sentence similarity based on cosine similarity
|
20 |
def sentence_similarity(sent1, sent2, stopwords):
|
21 |
words1 = nltk.word_tokenize(sent1)
|
22 |
+
words2 = nltk.word_tokenize sent2)
|
23 |
|
24 |
words1 = [word.lower() for word in words1 if word.isalnum()]
|
25 |
words2 = [word.lower() for word in words2 if word.isalnum()]
|
|
|
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)):
|
|
|
76 |
st.title("Article Summarizer")
|
77 |
user_article = st.text_area("Enter your article here:")
|
78 |
translate = st.checkbox("Translate Summary")
|
79 |
+
target_language = st.selectbox("Select Target Language", ["English", "French", "Spanish", "German"])
|
80 |
|
81 |
if st.button("Summarize"):
|
82 |
if user_article:
|
|
|
85 |
st.write(summary)
|
86 |
|
87 |
if translate:
|
88 |
+
if target_language == "English":
|
89 |
+
target_language_code = "en"
|
90 |
+
elif target_language == "French":
|
91 |
+
target_language_code = "fr"
|
92 |
+
elif target_language == "Spanish":
|
93 |
+
target_language_code = "es"
|
94 |
+
elif target_language == "German":
|
95 |
+
target_language_code = "de"
|
96 |
+
|
97 |
+
translator = Translator()
|
98 |
+
translated_summary = translator.translate(summary, dest=target_language_code)
|
99 |
+
st.subheader("Translated Summary:")
|
100 |
+
st.write(translated_summary.text)
|
101 |
else:
|
102 |
st.warning("Please enter an article to summarize.")
|