theekshana commited on
Commit
400b4d5
1 Parent(s): 06b581b

rouge score

Browse files
Files changed (3) hide show
  1. app.py +105 -5
  2. requirements.txt +0 -0
  3. rouge_evaluate.py +8 -0
app.py CHANGED
@@ -6,6 +6,7 @@ import nltk
6
  import validators
7
  import streamlit as st
8
  from summarizer import summarizer_init, summarizer_summarize
 
9
  from config import MODELS
10
  from warnings import filterwarnings
11
 
@@ -28,6 +29,11 @@ def initialize_app():
28
  "model_name": "Boardpac summarizer v1",
29
  "summarizer_type": "Map Reduce",
30
  "is_parameters_changed":False,
 
 
 
 
 
31
  # "user_question":'',
32
  'openai_api_key':'',
33
  }
@@ -155,6 +161,7 @@ def load_app():
155
  # inp_text = st.text_input(
156
  # "Enter text or a url here"
157
  # )
 
158
  inp_text = st.text_area(
159
  "Enter text here"
160
  )
@@ -177,7 +184,7 @@ def load_app():
177
  cleaned_txt = clean_text(cleaned_txt)
178
  else:
179
  logger.info("Text Input Type: INPUT TEXT")
180
- cleaned_txt = clean_text(inp_text)
181
 
182
  # view summarized text (expander)
183
  with st.expander("View input text"):
@@ -186,7 +193,14 @@ def load_app():
186
  else:
187
  st.write(cleaned_txt)
188
 
 
 
 
 
 
 
189
  submitted = st.button("Summarize")
 
190
 
191
  if submitted:
192
  if is_url:
@@ -194,11 +208,61 @@ def load_app():
194
  else:
195
  text_to_summarize = cleaned_txt
196
 
197
- submit_text_to_summarize(text_to_summarize)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
  def submit_text_to_summarize(text_to_summarize):
200
  summarized_text, time = get_summary(text_to_summarize)
 
201
  display_output(summarized_text,time)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
 
204
  def get_summary(text_to_summarize):
@@ -221,21 +285,57 @@ def get_summary(text_to_summarize):
221
  summarized_text, time = summarizer_summarize(model_type,tokenizer, base_summarizer, text_to_summarize ,summarizer_type = "map_reduce")
222
  return summarized_text, time
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
  def display_output(summarized_text,time):
226
  logger.info(f"SUMMARY: {summarized_text}")
227
  logger.info(f"Summary took {time}s")
228
  st.subheader("Summarized text")
229
  st.info(f"{summarized_text}")
230
- st.markdown(f"Time: {time}s")
231
-
232
 
233
  def main():
234
 
235
  initialize_app()
236
  side_bar()
237
  load_app()
238
- # chat_body()
239
 
240
 
241
  if __name__ == "__main__":
 
6
  import validators
7
  import streamlit as st
8
  from summarizer import summarizer_init, summarizer_summarize
9
+ from rouge_evaluate import get_rouge_scores
10
  from config import MODELS
11
  from warnings import filterwarnings
12
 
 
29
  "model_name": "Boardpac summarizer v1",
30
  "summarizer_type": "Map Reduce",
31
  "is_parameters_changed":False,
32
+ "is_evaluate_pressed":False,
33
+ "is_evaluate_pressed":False,
34
+ "reference_summary":'',
35
+ "generated_summary":'',
36
+ "summary_time":'',
37
  # "user_question":'',
38
  'openai_api_key':'',
39
  }
 
161
  # inp_text = st.text_input(
162
  # "Enter text or a url here"
163
  # )
164
+ # with st.form("Text Summarizer"):
165
  inp_text = st.text_area(
166
  "Enter text here"
167
  )
 
184
  cleaned_txt = clean_text(cleaned_txt)
185
  else:
186
  logger.info("Text Input Type: INPUT TEXT")
187
+ cleaned_txt = inp_text # clean_text(inp_text)
188
 
189
  # view summarized text (expander)
190
  with st.expander("View input text"):
 
193
  else:
194
  st.write(cleaned_txt)
195
 
196
+ st.subheader('Optional - Evaluate summary against a reference')
197
+ # with st.form('Evaluate summary against a reference'):
198
+ reference_summary = st.text_area(
199
+ "Enter reference summary here"
200
+ )
201
+
202
  submitted = st.button("Summarize")
203
+ # submitted = st.form_submit_button("Summarize")
204
 
205
  if submitted:
206
  if is_url:
 
208
  else:
209
  text_to_summarize = cleaned_txt
210
 
211
+ summarized_text=submit_text_to_summarize(text_to_summarize)
212
+ # summarized_text=submit_text_to_summarize2(text_to_summarize, reference_summary)
213
+ # "reference_summary":'',
214
+ # st.session_state.generated_summary=summarized_text
215
+ # evaluate_block(summarized_text)
216
+ # st.subheader('Evaluate summary against a reference')
217
+ # with st.form('Evaluate summary against a reference'):
218
+ # reference_summary = st.text_area(
219
+ # "Enter reference summary here"
220
+ # )
221
+ # Evaluate = st.button(
222
+ # "Evaluate",
223
+ # # on_click=update_evaluate_button_change,
224
+ # on_click=testtttt,
225
+ # # args=[summarized_text, reference_summary]
226
+ # )
227
+
228
+ # if Evaluate :
229
+ if reference_summary.strip() != '':
230
+ summarized_text=st.session_state.generated_summary
231
+ rouge_result = get_rouge_scores(summarized_text, clean_text(reference_summary))
232
+ # st.text(f"evaluate scores-----: {scores}")
233
+ # st.info("evaluate scores-----:")
234
+ # st.info("evaluated scores-----:")
235
+ # with st.expander(f"evaluated scores: rouge1: {scores['rouge1']:.2f}%"):
236
+ # st.table(scores)
237
+ st.text("Evaluated scores:")
238
+ col1, col2, col3 = st.columns(3)
239
+ col1.metric('Rogue1', "{:.2f}".format(rouge_result['rouge1']))
240
+ col2.metric('rouge2', "{:.2f}".format(rouge_result['rouge2']))
241
+ col3.metric('rougeL', "{:.2f}".format(rouge_result['rougeL']))
242
+ # col4.metric('rougeLsum', "{:.2f}".format(rouge_result['rougeLsum']))
243
+
244
+
245
 
246
  def submit_text_to_summarize(text_to_summarize):
247
  summarized_text, time = get_summary(text_to_summarize)
248
+ st.session_state.generated_summary=summarized_text
249
  display_output(summarized_text,time)
250
+ # evaluate_block(summarized_text)
251
+ # return summarized_text
252
+
253
+ def submit_text_to_summarize2(text_to_summarize, reference_summary):
254
+ summarized_text, time = get_summary(text_to_summarize)
255
+ # display_output(summarized_text,time)
256
+ logger.info(f"SUMMARY: {summarized_text}")
257
+ logger.info(f"Summary took {time}s")
258
+ st.subheader("Summarized text")
259
+ st.info(f"{summarized_text}")
260
+ # st.info(f"Time: {time}s")
261
+ st.text(f"Time taken: {time}s")
262
+
263
+ # scores = get_rouge_scores(summarized_text, reference_summary)
264
+ # st.markdown(f"evaluate scores: {scores}")
265
+
266
 
267
 
268
  def get_summary(text_to_summarize):
 
285
  summarized_text, time = summarizer_summarize(model_type,tokenizer, base_summarizer, text_to_summarize ,summarizer_type = "map_reduce")
286
  return summarized_text, time
287
 
288
+ def evaluate_block(summarized_text):
289
+ st.subheader('Evaluate summary against a reference')
290
+ # with st.form('Evaluate summary against a reference'):
291
+ reference_summary = st.text_area(
292
+ "Enter reference summary here"
293
+ )
294
+ Evaluate = st.button(
295
+ "Evaluate",
296
+ on_click=testtttt,
297
+ args=[summarized_text,reference_summary]
298
+ )
299
+
300
+ # Evaluate = st.form_submit_button(
301
+ # "Evaluate key",
302
+ # # on_click=update_parameters_change
303
+ # on_click=testtttt,
304
+ # args=[summarized_text,reference_summary]
305
+ # )
306
+ # if Evaluate or st.session_state.is_evaluate_pressed:
307
+ # if reference_summary:
308
+ # # if
309
+ # scores = get_rouge_scores(summarized_text, reference_summary)
310
+ # st.text(f"evaluate scores: {scores}")
311
+ # st.session_state.is_evaluate_pressed = False
312
+
313
+ def testtttt(summarized_text, reference_summary):
314
+ print(summarized_text, reference_summary)
315
+ scores = get_rouge_scores(summarized_text, reference_summary)
316
+ st.text(f"evaluate scores-----: {scores}")
317
+
318
+
319
+ def update_evaluate_button_change():
320
+ st.session_state.is_evaluate_pressed = True
321
+
322
+ # def evaluate(summarized_text, reference_summary):
323
+ # return get_rouge_scores(summarized_text, reference_summary)
324
+
325
 
326
  def display_output(summarized_text,time):
327
  logger.info(f"SUMMARY: {summarized_text}")
328
  logger.info(f"Summary took {time}s")
329
  st.subheader("Summarized text")
330
  st.info(f"{summarized_text}")
331
+ # st.info(f"Time: {time}s")
332
+ st.text(f"Time taken: {time}s")
333
 
334
  def main():
335
 
336
  initialize_app()
337
  side_bar()
338
  load_app()
 
339
 
340
 
341
  if __name__ == "__main__":
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
 
rouge_evaluate.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ import evaluate
2
+ rouge_score = evaluate.load("rouge")
3
+
4
+ def get_rouge_scores(genererated_summary:str,reference_summary:str)->dict:
5
+
6
+ rouge_result = rouge_score.compute(predictions=[genererated_summary], references=[reference_summary])
7
+
8
+ return rouge_result