Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -329,17 +329,18 @@ class PaperDownloader:
|
|
329 |
lambda: open(filepath, 'wb').write(pdf_content)
|
330 |
)
|
331 |
logger.info(f"Saved PDF to file: {filepath}")
|
332 |
-
|
333 |
-
logger.info(f"Descarga exitosa: {filename}")
|
334 |
progress_callback(f"Descargado exitosamente: <a href='https://doi.org/{doi}'>{doi}</a>")
|
335 |
return filepath, f'<a href="https://doi.org/{doi}">{doi}</a>', "", ""
|
336 |
else:
|
337 |
logger.warning(f"No se pudo descargar: {doi}")
|
|
|
338 |
progress_callback(f"No se pudo descargar: <a href='https://doi.org/{doi}'>{doi}</a>")
|
339 |
return None, f"No se pudo descargar {doi}", f'<a href="https://doi.org/{doi}">{doi}</a>', ""
|
340 |
|
341 |
except Exception as e:
|
342 |
logger.error(f"Error processing {doi}: {e}")
|
|
|
343 |
progress_callback(f"Error procesando {doi}: <a href='https://doi.org/{doi}'>{e}")
|
344 |
return None, f"Error procesando {doi}: {e}", f"Error processing {doi}: {e}", ""
|
345 |
|
@@ -407,7 +408,7 @@ class PaperDownloader:
|
|
407 |
except Exception as rename_error:
|
408 |
logger.error(f"Error renaming file for {doi}: {rename_error}")
|
409 |
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a> - Error saving file')
|
410 |
-
|
411 |
# Crear archivo ZIP si hay archivos descargados
|
412 |
zip_filename = None
|
413 |
if downloaded_files:
|
@@ -468,7 +469,7 @@ class PaperDownloader:
|
|
468 |
downloaded_links.append(f'<a href="https://doi.org/{dois[i]}">{dois[i]}</a>')
|
469 |
else:
|
470 |
failed_dois.append(f'<a href="https://doi.org/{dois[i]}">{dois[i]}</a>')
|
471 |
-
|
472 |
if downloaded_files:
|
473 |
zip_filename = 'papers.zip'
|
474 |
loop = asyncio.get_running_loop()
|
@@ -494,24 +495,28 @@ def create_gradio_interface():
|
|
494 |
|
495 |
def custom_progress_callback(message):
|
496 |
logger.info(f"Callback message: {message}")
|
|
|
497 |
return update_progress(message)
|
498 |
-
|
499 |
if bib_file:
|
500 |
# Check file type
|
501 |
if not bib_file.name.lower().endswith('.bib'):
|
502 |
return None, "Error: Please upload a .bib file", "Error: Please upload a .bib file", "", None
|
503 |
|
504 |
zip_path, downloaded_dois, failed_dois, _ = await downloader.process_bibtex_async(bib_file, custom_progress_callback)
|
|
|
505 |
return zip_path, downloaded_dois, failed_dois, "", None
|
506 |
elif doi_input:
|
507 |
filepath, message, failed_doi, _ = await downloader.download_single_doi_async(doi_input,custom_progress_callback)
|
|
|
508 |
return None, message, failed_doi, "", filepath
|
509 |
elif dois_input:
|
510 |
zip_path, downloaded_dois, failed_dois, _ = await downloader.download_multiple_dois_async(dois_input, custom_progress_callback)
|
|
|
511 |
return zip_path, downloaded_dois, failed_dois, "", None
|
512 |
else:
|
513 |
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
|
514 |
-
|
515 |
|
516 |
|
517 |
# Gradio Interface
|
|
|
329 |
lambda: open(filepath, 'wb').write(pdf_content)
|
330 |
)
|
331 |
logger.info(f"Saved PDF to file: {filepath}")
|
332 |
+
await asyncio.sleep(0.1) #force wait here
|
|
|
333 |
progress_callback(f"Descargado exitosamente: <a href='https://doi.org/{doi}'>{doi}</a>")
|
334 |
return filepath, f'<a href="https://doi.org/{doi}">{doi}</a>', "", ""
|
335 |
else:
|
336 |
logger.warning(f"No se pudo descargar: {doi}")
|
337 |
+
await asyncio.sleep(0.1) #force wait here
|
338 |
progress_callback(f"No se pudo descargar: <a href='https://doi.org/{doi}'>{doi}</a>")
|
339 |
return None, f"No se pudo descargar {doi}", f'<a href="https://doi.org/{doi}">{doi}</a>', ""
|
340 |
|
341 |
except Exception as e:
|
342 |
logger.error(f"Error processing {doi}: {e}")
|
343 |
+
await asyncio.sleep(0.1) #force wait here
|
344 |
progress_callback(f"Error procesando {doi}: <a href='https://doi.org/{doi}'>{e}")
|
345 |
return None, f"Error procesando {doi}: {e}", f"Error processing {doi}: {e}", ""
|
346 |
|
|
|
408 |
except Exception as rename_error:
|
409 |
logger.error(f"Error renaming file for {doi}: {rename_error}")
|
410 |
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a> - Error saving file')
|
411 |
+
await asyncio.sleep(0.1)
|
412 |
# Crear archivo ZIP si hay archivos descargados
|
413 |
zip_filename = None
|
414 |
if downloaded_files:
|
|
|
469 |
downloaded_links.append(f'<a href="https://doi.org/{dois[i]}">{dois[i]}</a>')
|
470 |
else:
|
471 |
failed_dois.append(f'<a href="https://doi.org/{dois[i]}">{dois[i]}</a>')
|
472 |
+
await asyncio.sleep(0.1) #force wait
|
473 |
if downloaded_files:
|
474 |
zip_filename = 'papers.zip'
|
475 |
loop = asyncio.get_running_loop()
|
|
|
495 |
|
496 |
def custom_progress_callback(message):
|
497 |
logger.info(f"Callback message: {message}")
|
498 |
+
|
499 |
return update_progress(message)
|
500 |
+
|
501 |
if bib_file:
|
502 |
# Check file type
|
503 |
if not bib_file.name.lower().endswith('.bib'):
|
504 |
return None, "Error: Please upload a .bib file", "Error: Please upload a .bib file", "", None
|
505 |
|
506 |
zip_path, downloaded_dois, failed_dois, _ = await downloader.process_bibtex_async(bib_file, custom_progress_callback)
|
507 |
+
await asyncio.sleep(0.1) #force wait
|
508 |
return zip_path, downloaded_dois, failed_dois, "", None
|
509 |
elif doi_input:
|
510 |
filepath, message, failed_doi, _ = await downloader.download_single_doi_async(doi_input,custom_progress_callback)
|
511 |
+
await asyncio.sleep(0.1) #force wait
|
512 |
return None, message, failed_doi, "", filepath
|
513 |
elif dois_input:
|
514 |
zip_path, downloaded_dois, failed_dois, _ = await downloader.download_multiple_dois_async(dois_input, custom_progress_callback)
|
515 |
+
await asyncio.sleep(0.1) #force wait
|
516 |
return zip_path, downloaded_dois, failed_dois, "", None
|
517 |
else:
|
518 |
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
|
519 |
+
|
520 |
|
521 |
|
522 |
# Gradio Interface
|