Gladiator commited on
Commit
ee790d1
1 Parent(s): fc9df0f

add rogue score

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -12,6 +12,8 @@ from utils import (
12
  read_text_from_file,
13
  )
14
 
 
 
15
  if __name__ == "__main__":
16
  # ---------------------------------
17
  # Main Application
@@ -63,28 +65,28 @@ if __name__ == "__main__":
63
  is_url = validators.url(inp_text)
64
  if is_url:
65
  # complete text, chunks to summarize (list of sentences for long docs)
66
- text, clean_txt = fetch_article_text(url=inp_text)
67
  elif uploaded_file:
68
- clean_txt = read_text_from_file(uploaded_file)
69
- clean_txt = clean_text(clean_txt)
70
  else:
71
- clean_txt = clean_text(inp_text)
72
 
73
  # view summarized text (expander)
74
  with st.expander("View input text"):
75
  if is_url:
76
- st.write(clean_txt[0])
77
  else:
78
- st.write(clean_txt)
79
  summarize = st.button("Summarize")
80
 
81
  # called on toggle button [summarize]
82
  if summarize:
83
  if summarize_type == "Extractive":
84
  if is_url:
85
- text_to_summarize = " ".join([txt for txt in clean_txt])
86
  else:
87
- text_to_summarize = clean_txt
88
  # extractive summarizer
89
 
90
  with st.spinner(
@@ -97,7 +99,7 @@ if __name__ == "__main__":
97
  with st.spinner(
98
  text="Creating abstractive summary. This might take a few seconds ..."
99
  ):
100
- text_to_summarize = clean_txt
101
  abs_summarizer = pipeline(
102
  "summarization", model=abs_model_name, tokenizer=abs_tokenizer_name
103
  )
@@ -105,7 +107,7 @@ if __name__ == "__main__":
105
  if is_url is False:
106
  # list of chunks
107
  text_to_summarize = preprocess_text_for_abstractive_summarization(
108
- tokenizer=abs_tokenizer, text=clean_txt
109
  )
110
 
111
  tmp_sum = abs_summarizer(
@@ -120,3 +122,7 @@ if __name__ == "__main__":
120
  # final summarized output
121
  st.subheader("Summarized text")
122
  st.info(summarized_text)
 
 
 
 
 
12
  read_text_from_file,
13
  )
14
 
15
+ from rouge import rouge
16
+
17
  if __name__ == "__main__":
18
  # ---------------------------------
19
  # Main Application
 
65
  is_url = validators.url(inp_text)
66
  if is_url:
67
  # complete text, chunks to summarize (list of sentences for long docs)
68
+ text, cleaned_txt = fetch_article_text(url=inp_text)
69
  elif uploaded_file:
70
+ cleaned_txt = read_text_from_file(uploaded_file)
71
+ cleaned_txt = clean_text(cleaned_txt)
72
  else:
73
+ cleaned_txt = clean_text(inp_text)
74
 
75
  # view summarized text (expander)
76
  with st.expander("View input text"):
77
  if is_url:
78
+ st.write(cleaned_txt[0])
79
  else:
80
+ st.write(cleaned_txt)
81
  summarize = st.button("Summarize")
82
 
83
  # called on toggle button [summarize]
84
  if summarize:
85
  if summarize_type == "Extractive":
86
  if is_url:
87
+ text_to_summarize = " ".join([txt for txt in cleaned_txt])
88
  else:
89
+ text_to_summarize = cleaned_txt
90
  # extractive summarizer
91
 
92
  with st.spinner(
 
99
  with st.spinner(
100
  text="Creating abstractive summary. This might take a few seconds ..."
101
  ):
102
+ text_to_summarize = cleaned_txt
103
  abs_summarizer = pipeline(
104
  "summarization", model=abs_model_name, tokenizer=abs_tokenizer_name
105
  )
 
107
  if is_url is False:
108
  # list of chunks
109
  text_to_summarize = preprocess_text_for_abstractive_summarization(
110
+ tokenizer=abs_tokenizer, text=cleaned_txt
111
  )
112
 
113
  tmp_sum = abs_summarizer(
 
122
  # final summarized output
123
  st.subheader("Summarized text")
124
  st.info(summarized_text)
125
+
126
+ st.subheader("Rogue Scores")
127
+ score = rouge.get_scores(summarized_text, cleaned_txt, avg=True)
128
+ st.write(score)