amirhoseinsedaghati
commited on
Update pages/Summarize_Text.py
Browse files- pages/Summarize_Text.py +22 -3
pages/Summarize_Text.py
CHANGED
@@ -4,6 +4,10 @@ from configs.download_files import FileDownloader
|
|
4 |
from configs.db_configs import add_one_item
|
5 |
from streamlit.components.v1 import html
|
6 |
from configs.html_features import set_image
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def summarize_text(text):
|
9 |
prefix = 'summarize: '
|
@@ -21,6 +25,11 @@ def summarize_text(text):
|
|
21 |
output_ids = model.generate(input_ids, max_new_tokens=round(len(input_ids[0]) * 1/2), do_sample=False)
|
22 |
summarized_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
23 |
return summarized_text
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
def main():
|
@@ -33,6 +42,7 @@ def main():
|
|
33 |
html(set_image(url), height=500, width=500)
|
34 |
with im3:
|
35 |
pass
|
|
|
36 |
text = st.text_area('Text Summarizer', placeholder='Enter your input text here ...', height=200, label_visibility='hidden')
|
37 |
|
38 |
if st.button('Summarize it'):
|
@@ -44,9 +54,18 @@ def main():
|
|
44 |
with st.expander('Summarized Text'):
|
45 |
summarized_text = summarize_text(text)
|
46 |
st.write(summarized_text)
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
else:
|
52 |
st.error('Please enter a non-empty text.')
|
|
|
4 |
from configs.db_configs import add_one_item
|
5 |
from streamlit.components.v1 import html
|
6 |
from configs.html_features import set_image
|
7 |
+
from rouge import Rouge
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
+
|
11 |
|
12 |
def summarize_text(text):
|
13 |
prefix = 'summarize: '
|
|
|
25 |
output_ids = model.generate(input_ids, max_new_tokens=round(len(input_ids[0]) * 1/2), do_sample=False)
|
26 |
summarized_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
27 |
return summarized_text
|
28 |
+
|
29 |
+
|
30 |
+
def validate_summarization(original_text, summarized_text):
|
31 |
+
rouge_score = Rouge()
|
32 |
+
return rouge_score.get_scores(summarized_text, original_text)
|
33 |
|
34 |
|
35 |
def main():
|
|
|
42 |
html(set_image(url), height=500, width=500)
|
43 |
with im3:
|
44 |
pass
|
45 |
+
|
46 |
text = st.text_area('Text Summarizer', placeholder='Enter your input text here ...', height=200, label_visibility='hidden')
|
47 |
|
48 |
if st.button('Summarize it'):
|
|
|
54 |
with st.expander('Summarized Text'):
|
55 |
summarized_text = summarize_text(text)
|
56 |
st.write(summarized_text)
|
57 |
+
|
58 |
+
col1, col2 = st.columns(2)
|
59 |
+
with col1:
|
60 |
+
with st.expander('Download Summarized Text'):
|
61 |
+
FileDownloader(summarized_text, 'txt').download()
|
62 |
+
|
63 |
+
with col2:
|
64 |
+
with st.expander('Summarized Text Validation'):
|
65 |
+
scores = validate_summarization(text, summarized_text)
|
66 |
+
df = pd.DataFrame(scores[0]).T
|
67 |
+
df.columns = ['Recall', 'Precision', 'F1']
|
68 |
+
st.write(df)
|
69 |
|
70 |
else:
|
71 |
st.error('Please enter a non-empty text.')
|