C2MV commited on
Commit
18d63b3
·
verified ·
1 Parent(s): d516500

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -28
app.py CHANGED
@@ -397,10 +397,10 @@ class PaperDownloader:
397
 
398
 
399
  for doi in dois:
400
- self._download_single_doi(doi, lambda a,b,c: progress_callback(a,b,c, doi) , cancel_event )
401
  if cancel_event.is_set():
402
  logger.info("Downloads cancelled on multiple dois download")
403
- progress_callback(None, "Downloads cancelled","Downloads cancelled") # early return on cancelled
404
  return None #break here when is cancelled
405
 
406
  result = self.results_dict.get(doi, (None,None,"")) # obtain from self.results
@@ -456,7 +456,7 @@ class PaperDownloader:
456
 
457
 
458
  # Devolver resultados
459
- progress_callback( zip_filename if downloaded_files else None, "\n".join(downloaded_links),"\n".join(failed_dois))
460
  return
461
 
462
  def process_bibtex(self, bib_file, progress_callback, cancel_event):# removed async here
@@ -489,10 +489,10 @@ class PaperDownloader:
489
 
490
  for doi in dois:
491
 
492
- self._download_single_doi(doi, lambda a,b,c: progress_callback(a,b,c, doi), cancel_event )
493
  if cancel_event.is_set():
494
  logger.info("Download Cancelled in bibtex mode")
495
- progress_callback(None, "Download Cancelled", "Download Cancelled")
496
  return None #cancel if requested
497
 
498
  result = self.results_dict.get(doi, (None,None,"")) # obtain from self.results
@@ -527,7 +527,7 @@ class PaperDownloader:
527
  loop.run_in_executor(self.executor, lambda: self.create_zip(zip_filename,downloaded_files))
528
  logger.info(f"ZIP file created: {zip_filename}")
529
 
530
- progress_callback(zip_filename, "\n".join(downloaded_links), "\n".join(failed_dois)) #after process finishes
531
  return
532
 
533
  def create_zip(self, zip_filename, files):
@@ -564,47 +564,46 @@ def create_gradio_interface():
564
  if doi:
565
  downloader.results_dict[doi] = (filepath, message,fail_message)
566
 
567
- updates = update_progress(message,fail_message) #use update function here
568
  return updates
569
 
570
  if bib_file:
571
  # Check file type
572
  if not bib_file.name.lower().endswith('.bib'):
573
- return None, "Error: Please upload a .bib file", "Error: Please upload a .bib file", None
574
 
575
  downloader.download_task = downloader.executor.submit(
576
  downloader.process_bibtex,
577
  bib_file,
578
- lambda a,b,c: update_progress(a,f"{b}<br>{c}"), #convert for ui output, the return data will contain the HTML
579
- cancel_event # Added cancelllation event.
580
- )
581
-
582
- return None,"","",None
583
 
584
  elif doi_input:
585
 
586
- downloader.download_task = downloader.executor.submit( #changed async execution method
587
  downloader._download_single_doi,
588
- doi_input,
589
- lambda a,b,c: update_progress(a,f"{b}<br>{c}") , #callback function, format output and send html info, removed lambda from executor calls
590
  cancel_event # Add cancellation event.
591
- )
592
 
593
- return None, "","", None
594
-
595
  elif dois_input:
596
- downloader.download_task = downloader.executor.submit( #changed async execution method
597
- downloader.download_multiple_dois,
598
- dois_input,
599
- lambda a,b,c: update_progress(a,f"{b}<br>{c}") ,#callback function
600
- cancel_event #Add cancellation event.
601
  )
602
-
603
- return None, "","", None
604
 
605
  else:
606
- return None, "Please provide a .bib file, a single DOI, or a list of DOIs", "Please provide a .bib file, a single DOI, or a list of DOIs","", None
607
-
608
 
609
 
610
  with gr.Blocks(theme="Hev832/Applio", css="""
 
397
 
398
 
399
  for doi in dois:
400
+ self._download_single_doi(doi, lambda a,b,c,d: progress_callback(a,b,c,d) , cancel_event ) # changed lambda
401
  if cancel_event.is_set():
402
  logger.info("Downloads cancelled on multiple dois download")
403
+ progress_callback(None, "Downloads cancelled","Downloads cancelled", ) # early return on cancelled
404
  return None #break here when is cancelled
405
 
406
  result = self.results_dict.get(doi, (None,None,"")) # obtain from self.results
 
456
 
457
 
458
  # Devolver resultados
459
+ progress_callback( zip_filename if downloaded_files else None, "\n".join(downloaded_links),"\n".join(failed_dois), "")
460
  return
461
 
462
  def process_bibtex(self, bib_file, progress_callback, cancel_event):# removed async here
 
489
 
490
  for doi in dois:
491
 
492
+ self._download_single_doi(doi, lambda a,b,c, d: progress_callback(a,b,c, d), cancel_event ) # changed lambda
493
  if cancel_event.is_set():
494
  logger.info("Download Cancelled in bibtex mode")
495
+ progress_callback(None, "Download Cancelled", "Download Cancelled", )
496
  return None #cancel if requested
497
 
498
  result = self.results_dict.get(doi, (None,None,"")) # obtain from self.results
 
527
  loop.run_in_executor(self.executor, lambda: self.create_zip(zip_filename,downloaded_files))
528
  logger.info(f"ZIP file created: {zip_filename}")
529
 
530
+ progress_callback(zip_filename, "\n".join(downloaded_links), "\n".join(failed_dois), "") # send 4 vars
531
  return
532
 
533
  def create_zip(self, zip_filename, files):
 
564
  if doi:
565
  downloader.results_dict[doi] = (filepath, message,fail_message)
566
 
567
+ updates = update_progress(message, fail_message)
568
  return updates
569
 
570
  if bib_file:
571
  # Check file type
572
  if not bib_file.name.lower().endswith('.bib'):
573
+ return None, "Error: Please upload a .bib file", "Error: Please upload a .bib file", "",""
574
 
575
  downloader.download_task = downloader.executor.submit(
576
  downloader.process_bibtex,
577
  bib_file,
578
+ lambda a,b,c,d : update_progress(a,f"{b}<br>{c}"), #convert for ui output, the return data will contain the HTML
579
+ cancel_event # Added cancelllation event.
580
+ )
581
+
582
+ return None,"","", "", None # output here correct
583
 
584
  elif doi_input:
585
 
586
+ downloader.download_task = downloader.executor.submit( #changed async execution method
587
  downloader._download_single_doi,
588
+ doi_input,
589
+ lambda a,b,c,d: update_progress(a,f"{b}<br>{c}") , #callback function, format output and send html info, removed lambda from executor calls
590
  cancel_event # Add cancellation event.
591
+ )
592
 
593
+ return None, "","", "", None # output here correct
594
+
595
  elif dois_input:
596
+ downloader.download_task = downloader.executor.submit( #changed async execution method
597
+ downloader.download_multiple_dois,
598
+ dois_input,
599
+ lambda a,b,c,d: update_progress(a,f"{b}<br>{c}") ,#callback function
600
+ cancel_event #Add cancellation event.
601
  )
602
+
603
+ return None, "","", "", None #output here correct
604
 
605
  else:
606
+ return None, "Please provide a .bib file, a single DOI, or a list of DOIs", "Please provide a .bib file, a single DOI, or a list of DOIs","", None #output here correct
 
607
 
608
 
609
  with gr.Blocks(theme="Hev832/Applio", css="""