Files changed (3) hide show
  1. app.py +4 -3
  2. controlled_summarization.py +10 -3
  3. description.py +0 -2
app.py CHANGED
@@ -29,10 +29,9 @@ with gr.Blocks(css="#htext span {white-space: pre-line}") as demo:
29
  ctrlsum_file = gr.File(label="Input File")
30
  ctrlsum_str = gr.TextArea(label="Input String", max_lines=5)
31
  with gr.Column():
32
- gr.Markdown("* Set the length of text used for summarization. Length 0 will exert no control over length.")
33
  # ctrlsum_file_beams = gr.Number(label="Number of beams for beam search", value=1, precision=0)
34
  # ctrlsum_file_sequences = gr.Number(label="Number of generated summaries", value=1, precision=0)
35
- ctrlsum_file_length = gr.Radio(label="Length", value=0, choices=[0, 50, 100, 200])
36
  kw = gr.Radio(visible=False)
37
  ctrlsum_file_keywords = gr.Textbox(label="Keywords", max_lines=1)
38
  with gr.Row():
@@ -40,6 +39,8 @@ with gr.Blocks(css="#htext span {white-space: pre-line}") as demo:
40
  ctrlsum_file_output = gr.Textbox(
41
  elem_id="htext",
42
  label="Summary",
 
 
43
  )
44
  ctrlsum_file_examples = gr.Examples(
45
  examples=[["examples/H01-1042_body.txt", 50, "automatic evaluation technique", "", ""],
@@ -185,4 +186,4 @@ with gr.Blocks(css="#htext span {white-space: pre-line}") as demo:
185
  )
186
 
187
 
188
- demo.launch(share=False)
 
29
  ctrlsum_file = gr.File(label="Input File")
30
  ctrlsum_str = gr.TextArea(label="Input String", max_lines=5)
31
  with gr.Column():
 
32
  # ctrlsum_file_beams = gr.Number(label="Number of beams for beam search", value=1, precision=0)
33
  # ctrlsum_file_sequences = gr.Number(label="Number of generated summaries", value=1, precision=0)
34
+ ctrlsum_file_length = gr.Radio(label="Length", value=0, choices=[0, 50, 100, 200], info="Set the maximum limit for the length of text generated in the output summary. Length 0 implies no restriction on the summary length.")
35
  kw = gr.Radio(visible=False)
36
  ctrlsum_file_keywords = gr.Textbox(label="Keywords", max_lines=1)
37
  with gr.Row():
 
39
  ctrlsum_file_output = gr.Textbox(
40
  elem_id="htext",
41
  label="Summary",
42
+ show_label=True,
43
+ show_copy_button=True
44
  )
45
  ctrlsum_file_examples = gr.Examples(
46
  examples=[["examples/H01-1042_body.txt", 50, "automatic evaluation technique", "", ""],
 
186
  )
187
 
188
 
189
+ demo.queue().launch(share=False)
controlled_summarization.py CHANGED
@@ -3,6 +3,7 @@ import torch
3
  from SciAssist import Summarization
4
  import os
5
  import requests
 
6
  from datasets import load_dataset
7
  print(f"Is CUDA available: {torch.cuda.is_available()}")
8
  # True
@@ -107,7 +108,8 @@ def ctrlsum_for_str(input, length=None, keywords=None) -> List[Tuple[str, str]]:
107
  def ctrlsum_for_file(input=None, length=None, keywords="", text="", url="") -> List[Tuple[str, str, str]]:
108
  if input == None and url == "":
109
  if text == "":
110
- return None, "Input cannot be left blank.", None
 
111
  else:
112
  return ctrlsum_for_str(text, length, keywords), text, None
113
  else:
@@ -132,7 +134,8 @@ def ctrlsum_for_file(input=None, length=None, keywords="", text="", url="") -> L
132
 
133
  filename = download_pdf(url, './cache/')
134
  else:
135
- "Invalid url(Not PDF)!", None, None
 
136
  else:
137
  filename = input.name
138
  if keywords != "":
@@ -150,11 +153,15 @@ def ctrlsum_for_file(input=None, length=None, keywords="", text="", url="") -> L
150
  results = ctrlsum_pipeline.predict(filename,
151
  save_results=False, length=length, keywords=keywords, num_beams=1)
152
  else:
153
- return "File Format Error !", None, filename
 
154
 
155
  output = []
156
  for res in results["summary"]:
157
  output.append(f"{res}\n\n")
 
 
 
158
  return "".join(output), results["raw_text"], filename
159
 
160
 
 
3
  from SciAssist import Summarization
4
  import os
5
  import requests
6
+ import gradio as gr
7
  from datasets import load_dataset
8
  print(f"Is CUDA available: {torch.cuda.is_available()}")
9
  # True
 
108
  def ctrlsum_for_file(input=None, length=None, keywords="", text="", url="") -> List[Tuple[str, str, str]]:
109
  if input == None and url == "":
110
  if text == "":
111
+ gr.Warning("Input cannot be left blank!")
112
+ return None, None, None
113
  else:
114
  return ctrlsum_for_str(text, length, keywords), text, None
115
  else:
 
134
 
135
  filename = download_pdf(url, './cache/')
136
  else:
137
+ gr.Warning("Invalid URL (Not PDF)!")
138
+ return None, None, None
139
  else:
140
  filename = input.name
141
  if keywords != "":
 
153
  results = ctrlsum_pipeline.predict(filename,
154
  save_results=False, length=length, keywords=keywords, num_beams=1)
155
  else:
156
+ gr.Warning("File Format Error! Please upload .txt or .pdf files.")
157
+ return None, None, None
158
 
159
  output = []
160
  for res in results["summary"]:
161
  output.append(f"{res}\n\n")
162
+ if results["raw_text"] == "":
163
+ gr.Warning("Unable to parse File! Please try a different file.")
164
+ return None, None, None
165
  return "".join(output), results["raw_text"], filename
166
 
167
 
description.py CHANGED
@@ -44,8 +44,6 @@ To **test on strings**, simply input a string.
44
  '''
45
 
46
  ctrlsum_file_md = '''
47
- This is the demo for **CocoSciSum**.
48
-
49
  ## Controlled Summarization uses FLAN-T5 to generate user-customised summaries from your input file or URL link.
50
 
51
  To **test on a file**, the input can be:
 
44
  '''
45
 
46
  ctrlsum_file_md = '''
 
 
47
  ## Controlled Summarization uses FLAN-T5 to generate user-customised summaries from your input file or URL link.
48
 
49
  To **test on a file**, the input can be: