Spaces:
Sleeping
Sleeping
Add error message.
Browse files- controlled_summarization.py +6 -3
- description.py +0 -2
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,7 @@ 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 |
-
|
111 |
else:
|
112 |
return ctrlsum_for_str(text, length, keywords), text, None
|
113 |
else:
|
@@ -132,7 +133,7 @@ def ctrlsum_for_file(input=None, length=None, keywords="", text="", url="") -> L
|
|
132 |
|
133 |
filename = download_pdf(url, './cache/')
|
134 |
else:
|
135 |
-
"Invalid
|
136 |
else:
|
137 |
filename = input.name
|
138 |
if keywords != "":
|
@@ -150,11 +151,13 @@ 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 |
-
|
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 |
+
raise gr.Error("Input cannot be left blank!")
|
112 |
else:
|
113 |
return ctrlsum_for_str(text, length, keywords), text, None
|
114 |
else:
|
|
|
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 |
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 |
|
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:
|