JavonTeo commited on
Commit
5ea2622
·
1 Parent(s): 4bda7af

Changed error message to warning messages.

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. controlled_summarization.py +8 -4
app.py CHANGED
@@ -185,4 +185,4 @@ with gr.Blocks(css="#htext span {white-space: pre-line}") as demo:
185
  )
186
 
187
 
188
- demo.launch(share=False)
 
185
  )
186
 
187
 
188
+ demo.queue().launch(share=False)
controlled_summarization.py CHANGED
@@ -108,7 +108,8 @@ def ctrlsum_for_str(input, length=None, keywords=None) -> List[Tuple[str, str]]:
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
- raise gr.Error("Input cannot be left blank!")
 
112
  else:
113
  return ctrlsum_for_str(text, length, keywords), text, None
114
  else:
@@ -133,7 +134,8 @@ def ctrlsum_for_file(input=None, length=None, keywords="", text="", url="") -> L
133
 
134
  filename = download_pdf(url, './cache/')
135
  else:
136
- raise gr.Error("Invalid URL (Not PDF)!")
 
137
  else:
138
  filename = input.name
139
  if keywords != "":
@@ -151,13 +153,15 @@ def ctrlsum_for_file(input=None, length=None, keywords="", text="", url="") -> L
151
  results = ctrlsum_pipeline.predict(filename,
152
  save_results=False, length=length, keywords=keywords, num_beams=1)
153
  else:
154
- raise gr.Error("File Format Error! Please upload .txt or .pdf files.")
 
155
 
156
  output = []
157
  for res in results["summary"]:
158
  output.append(f"{res}\n\n")
159
  if results["raw_text"] == "":
160
- raise gr.Error("Unable to parse File! Please try a different file.")
 
161
  return "".join(output), results["raw_text"], filename
162
 
163
 
 
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