Spaces:
Runtime error
Runtime error
fix: Add alternative error handling and queueing
Browse files- app.py +8 -3
- util/summarizer.py +29 -29
app.py
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from util import summarizer, textproc
|
| 3 |
from util.examples import entries
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
model_collection = summarizer.init_models()
|
| 6 |
patent_summarizer = summarizer.PatentSummarizer(model_collection)
|
| 7 |
iface = gr.Interface(
|
|
@@ -66,7 +70,8 @@ iface = gr.Interface(
|
|
| 66 |
https://arxiv.org/abs/1910.13461, https://huggingface.co/sshleifer/distilbart-cnn-6-6
|
| 67 |
🤖 PEGASUS: Pre-training with Extracted Gap-sentences for Abstractive Summarization
|
| 68 |
https://arxiv.org/abs/1912.08777 , https://huggingface.co/google/pegasus-xsum
|
| 69 |
-
"""
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from util import summarizer, textproc
|
| 3 |
from util.examples import entries
|
| 4 |
+
import importlib
|
| 5 |
+
|
| 6 |
+
importlib.reload(summarizer)
|
| 7 |
+
importlib.reload(textproc)
|
| 8 |
+
|
| 9 |
model_collection = summarizer.init_models()
|
| 10 |
patent_summarizer = summarizer.PatentSummarizer(model_collection)
|
| 11 |
iface = gr.Interface(
|
|
|
|
| 70 |
https://arxiv.org/abs/1910.13461, https://huggingface.co/sshleifer/distilbart-cnn-6-6
|
| 71 |
🤖 PEGASUS: Pre-training with Extracted Gap-sentences for Abstractive Summarization
|
| 72 |
https://arxiv.org/abs/1912.08777 , https://huggingface.co/google/pegasus-xsum
|
| 73 |
+
""",
|
| 74 |
+
|
| 75 |
)
|
| 76 |
|
| 77 |
+
iface.launch(enable_queue=True)
|
util/summarizer.py
CHANGED
|
@@ -26,7 +26,7 @@ class PatentSummarizer():
|
|
| 26 |
parsed_info = textproc.retrieve_parsed_doc(patent_information,
|
| 27 |
summaries_generated)
|
| 28 |
if parsed_info is None:
|
| 29 |
-
return ["[ERROR] Invalid
|
| 30 |
|
| 31 |
abstract, background, claims = parsed_info
|
| 32 |
summaries = list()
|
|
@@ -35,46 +35,46 @@ class PatentSummarizer():
|
|
| 35 |
if "Abstract" in summaries_generated and abstract is not None:
|
| 36 |
abstract = abstract[0: textproc.get_word_index(abstract, word_limit)]
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
summaries.append(abstract_summary)
|
| 41 |
else:
|
| 42 |
summaries.append(None)
|
| 43 |
-
|
| 44 |
-
summaries.append(None)
|
| 45 |
-
print(f'[ERROR] {e}')
|
| 46 |
-
|
| 47 |
-
try:
|
| 48 |
if "Background" in summaries_generated and background is not None:
|
| 49 |
background = background[0: textproc.get_word_index(background, word_limit)]
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
summaries.append(background_summary)
|
| 54 |
else:
|
| 55 |
summaries.append(None)
|
| 56 |
-
|
| 57 |
-
summaries.append(None)
|
| 58 |
-
print(f'[ERROR] {e}')
|
| 59 |
-
|
| 60 |
-
try:
|
| 61 |
if "Claims" in summaries_generated and claims is not None:
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
summaries.append(claims_summary)
|
| 74 |
else:
|
| 75 |
summaries.append(None)
|
| 76 |
-
except Exception as e:
|
| 77 |
-
summaries.append(None)
|
| 78 |
-
print(f'[ERROR] {e}')
|
| 79 |
|
| 80 |
return summaries
|
|
|
|
|
|
|
|
|
| 26 |
parsed_info = textproc.retrieve_parsed_doc(patent_information,
|
| 27 |
summaries_generated)
|
| 28 |
if parsed_info is None:
|
| 29 |
+
return ["[ERROR] Invalid patent information or timeout from scraping.", None, None]
|
| 30 |
|
| 31 |
abstract, background, claims = parsed_info
|
| 32 |
summaries = list()
|
|
|
|
| 35 |
if "Abstract" in summaries_generated and abstract is not None:
|
| 36 |
abstract = abstract[0: textproc.get_word_index(abstract, word_limit)]
|
| 37 |
|
| 38 |
+
try:
|
| 39 |
+
abstract_summary = self.model[abstract_model](abstract)
|
| 40 |
+
abstract_summary = textproc.post_process(abstract_summary)
|
| 41 |
+
except:
|
| 42 |
+
abstract_summary = None
|
| 43 |
summaries.append(abstract_summary)
|
| 44 |
else:
|
| 45 |
summaries.append(None)
|
| 46 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if "Background" in summaries_generated and background is not None:
|
| 48 |
background = background[0: textproc.get_word_index(background, word_limit)]
|
| 49 |
|
| 50 |
+
try:
|
| 51 |
+
background_summary = self.model[background_model](background)
|
| 52 |
+
background_summary = textproc.post_process(background_summary)
|
| 53 |
+
except:
|
| 54 |
+
background_summary = None
|
| 55 |
summaries.append(background_summary)
|
| 56 |
else:
|
| 57 |
summaries.append(None)
|
| 58 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
if "Claims" in summaries_generated and claims is not None:
|
| 60 |
+
try:
|
| 61 |
+
if collate_claims:
|
| 62 |
+
claims = ' '.join(claims)
|
| 63 |
+
print(len(claims))
|
| 64 |
+
claims = claims[0: textproc.get_word_index(claims, word_limit)]
|
| 65 |
+
print(len(claims))
|
| 66 |
+
claims_summary = self.model[claims_model](claims)
|
| 67 |
+
else:
|
| 68 |
+
claims_summary = ''
|
| 69 |
+
for claim in claims:
|
| 70 |
+
claims_summary += self.model[claims_model](claim)
|
| 71 |
+
claims_summary = textproc.post_process(claims_summary)
|
| 72 |
+
except:
|
| 73 |
+
claims_summary = None
|
| 74 |
summaries.append(claims_summary)
|
| 75 |
else:
|
| 76 |
summaries.append(None)
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
return summaries
|
| 79 |
+
except Exception as e:
|
| 80 |
+
return [f'[ERROR] {e}'] + [None]*(len(summaries_generated) - 1)
|