raannakasturi commited on
Commit
2bf3be5
·
1 Parent(s): 19f6a3d

Implement retry mechanism for summarizing papers in paper_data function

Browse files
Files changed (1) hide show
  1. main.py +17 -2
main.py CHANGED
@@ -1,5 +1,6 @@
1
  import json
2
  import os
 
3
  import dotenv
4
  import html
5
  from summarize_paper import summarize_paper
@@ -36,9 +37,23 @@ def paper_data(paper_data, wait_time=5):
36
  if not all([paper_id, doi, pdf_url, title, citation]):
37
  print(f"Skipping paper with ID: {paper_id} (missing details)")
38
  continue
39
- summary, mindmap = summarize_paper(pdf_url, paper_id, access_key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  if not summary or not mindmap:
41
- print(f"Skipping paper with ID: {paper_id} (Summary/Mindmap not found)")
42
  continue
43
  try:
44
  title = fix_text(title)
 
1
  import json
2
  import os
3
+ import time
4
  import dotenv
5
  import html
6
  from summarize_paper import summarize_paper
 
37
  if not all([paper_id, doi, pdf_url, title, citation]):
38
  print(f"Skipping paper with ID: {paper_id} (missing details)")
39
  continue
40
+ summary = None
41
+ mindmap = None
42
+ max_retries = 3
43
+ retry_count = 0
44
+ while (not summary or not mindmap) and retry_count < max_retries:
45
+ try:
46
+ summary, mindmap = summarize_paper(pdf_url, paper_id, access_key)
47
+ if summary and mindmap:
48
+ break
49
+ except Exception as e:
50
+ print(f"Error summarizing paper {paper_id}: {e}")
51
+ retry_count += 1
52
+ if retry_count < max_retries:
53
+ print(f"Retrying paper {paper_id} in 3 minutes")
54
+ time.sleep(3*60)
55
  if not summary or not mindmap:
56
+ print(f"Failed to summarize paper {paper_id} after {max_retries} attempts")
57
  continue
58
  try:
59
  title = fix_text(title)