Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -565,83 +565,49 @@ def create_gradio_interface():
|
|
565 |
downloader.results_dict[doi] = (filepath, message,fail_message)
|
566 |
|
567 |
updates = update_progress(message,fail_message) #use update function here
|
568 |
-
|
569 |
return updates
|
570 |
-
|
571 |
|
572 |
if bib_file:
|
573 |
-
|
574 |
if not bib_file.name.lower().endswith('.bib'):
|
575 |
-
|
576 |
-
|
577 |
downloader.download_task = downloader.executor.submit(
|
578 |
downloader.process_bibtex,
|
579 |
-
|
580 |
lambda a,b,c: update_progress(a,f"{b}<br>{c}"), #convert for ui output, the return data will contain the HTML
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
return None,"","",None
|
585 |
-
|
586 |
elif doi_input:
|
587 |
-
|
588 |
-
|
589 |
downloader._download_single_doi,
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
)
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
elif dois_input:
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
lambda a,b,c: update_progress(a,f"{b}<br>{c}") ,#callback function
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
|
607 |
else:
|
608 |
-
|
609 |
|
610 |
|
611 |
|
612 |
-
|
613 |
-
# Gradio Interface
|
614 |
-
interface = gr.Interface(
|
615 |
-
fn=download_papers,
|
616 |
-
inputs=[
|
617 |
-
gr.File(file_types=['.bib'], label="Upload BibTeX File"),
|
618 |
-
gr.Textbox(label="Enter Single DOI", placeholder="10.xxxx/xxxx"),
|
619 |
-
gr.Textbox(label="Enter Multiple DOIs (one per line)", placeholder="10.xxxx/xxxx\n10.yyyy/yyyy\n..."),
|
620 |
-
|
621 |
-
],
|
622 |
-
outputs=[
|
623 |
-
gr.File(label="Download Papers (ZIP) or Single PDF"),
|
624 |
-
gr.Textbox(label="""
|
625 |
-
Found DOIs
|
626 |
-
"""),
|
627 |
-
gr.Textbox(label="""
|
628 |
-
Missed DOIs
|
629 |
-
"""),
|
630 |
-
gr.Textbox(label="""
|
631 |
-
Logs
|
632 |
-
""", lines = 10),
|
633 |
-
gr.File(label="Downloaded Single PDF")
|
634 |
-
],
|
635 |
-
|
636 |
-
title="🔬 Academic Paper Batch Downloader",
|
637 |
-
description="Upload a BibTeX file or enter DOIs to download PDFs. We'll attempt to fetch PDFs from multiple sources like Sci-Hub, Libgen, Google Scholar and Crossref. You can use any of the three inputs at any moment.",
|
638 |
-
theme="Hev832/Applio",
|
639 |
-
examples=[
|
640 |
-
["example.bib", None, None], # Bibtex File
|
641 |
-
[None, "10.1038/nature12373", None], # Single DOI
|
642 |
-
[None, None, "10.1109/5.771073\n10.3390/horticulturae8080677"], # Multiple DOIs
|
643 |
-
],
|
644 |
-
css="""
|
645 |
.gradio-container {
|
646 |
background-color: black;
|
647 |
}
|
@@ -660,26 +626,56 @@ def create_gradio_interface():
|
|
660 |
.logs_box {
|
661 |
|
662 |
}
|
663 |
-
"""
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
|
678 |
-
|
679 |
-
|
680 |
-
|
|
|
|
|
|
|
|
|
681 |
|
|
|
|
|
|
|
682 |
return interface
|
|
|
683 |
|
684 |
def main():
|
685 |
interface = create_gradio_interface()
|
|
|
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="""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
.gradio-container {
|
612 |
background-color: black;
|
613 |
}
|
|
|
626 |
.logs_box {
|
627 |
|
628 |
}
|
629 |
+
""") as interface:
|
630 |
+
with gr.Row():
|
631 |
+
with gr.Column():
|
632 |
+
bib_file = gr.File(file_types=['.bib'], label="Upload BibTeX File")
|
633 |
+
doi_input = gr.Textbox(label="Enter Single DOI", placeholder="10.xxxx/xxxx")
|
634 |
+
dois_input = gr.Textbox(label="Enter Multiple DOIs (one per line)", placeholder="10.xxxx/xxxx\n10.yyyy/yyyy\n...")
|
635 |
+
with gr.Row():
|
636 |
+
clear_button= gr.ClearButton(value = "Clear") # added a clear button
|
637 |
+
submit_button= gr.Button(value="Submit")
|
638 |
+
examples= gr.Examples([
|
639 |
+
["example.bib", None, None], # Bibtex File
|
640 |
+
[None, "10.1038/nature12373", None], # Single DOI
|
641 |
+
[None, None, "10.1109/5.771073\n10.3390/horticulturae8080677"], # Multiple DOIs
|
642 |
+
],
|
643 |
+
inputs=[bib_file, doi_input, dois_input]
|
644 |
+
)
|
645 |
+
|
646 |
+
with gr.Column():
|
647 |
+
|
648 |
+
|
649 |
+
output_file = gr.File(label="Download Papers (ZIP) or Single PDF")
|
650 |
+
downloaded_dois_textbox = gr.Textbox(label="""
|
651 |
+
Found DOIs
|
652 |
+
""",)
|
653 |
+
failed_dois_textbox=gr.Textbox(label="""
|
654 |
+
Missed DOIs
|
655 |
+
""",)
|
656 |
+
logs = gr.Textbox(label="""
|
657 |
+
Logs
|
658 |
+
""", lines = 10)
|
659 |
+
|
660 |
+
single_file= gr.File(label="Downloaded Single PDF")
|
661 |
+
|
662 |
+
|
663 |
+
with gr.Row():
|
664 |
+
stop_button = gr.Button(value="Stop Downloads")
|
665 |
|
666 |
+
submit_button.click(
|
667 |
+
download_papers,
|
668 |
+
inputs=[bib_file, doi_input, dois_input],
|
669 |
+
outputs=[output_file, downloaded_dois_textbox, failed_dois_textbox,logs, single_file ] # the new output should be a tuple and we output logs too for debugging.
|
670 |
+
)
|
671 |
+
stop_button.click(lambda: downloader.cancel_download(), outputs=None) # added function in object downloader
|
672 |
+
|
673 |
|
674 |
+
interface.title="🔬 Academic Paper Batch Downloader"
|
675 |
+
interface.description="Upload a BibTeX file or enter DOIs to download PDFs. We'll attempt to fetch PDFs from multiple sources like Sci-Hub, Libgen, Google Scholar and Crossref. You can use any of the three inputs at any moment."
|
676 |
+
|
677 |
return interface
|
678 |
+
|
679 |
|
680 |
def main():
|
681 |
interface = create_gradio_interface()
|