C2MV commited on
Commit
99cc683
·
verified ·
1 Parent(s): b5bce76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -53
app.py CHANGED
@@ -414,8 +414,7 @@ def create_gradio_interface():
414
  return report_path
415
  return None
416
 
417
-
418
- # Gradio Interface
419
  downloaded_dois_html = gr.HTML(label="""
420
  <div style='padding-bottom: 5px; font-weight: bold;'>
421
  Enter Single DOI
@@ -435,51 +434,40 @@ def create_gradio_interface():
435
  <div id="failed-dois"></div>
436
  </div>
437
  """)
438
-
439
-
440
- interface = gr.Interface(
441
- fn=download_papers,
442
- inputs=[
443
- gr.File(file_types=['.bib'], label="Upload BibTeX File"),
444
- gr.Textbox(label="Enter Single DOI", placeholder="10.xxxx/xxxx"),
445
- gr.Textbox(label="Enter Multiple DOIs (one per line)", placeholder="10.xxxx/xxxx\n10.yyyy/yyyy\n...")
446
- ],
447
- outputs=[
448
- gr.File(label="Download Papers (ZIP) or Single PDF"),
449
- downloaded_dois_html,
450
- failed_dois_html,
451
- gr.File(label="Downloaded Single PDF"),
452
- ],
453
- title="🔬 Academic Paper Batch Downloader",
454
- 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.",
455
- theme="Hev832/Applio",
456
- examples=[
457
- ["example.bib", None, None], # Bibtex File
458
- [None, "10.1038/nature12373", None], # Single DOI
459
- [None, None, "10.1109/5.771073\n10.3390/horticulturae8080677"], # Multiple DOIs
460
- ],
461
- css="""
462
- .gradio-container {
463
- background-color: black;
464
- }
465
- .gr-interface {
466
- max-width: 800px;
467
- margin: 0 auto;
468
- }
469
- .gr-box {
470
- background-color: black;
471
- border-radius: 10px;
472
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
473
- }
474
- .output-text a {
475
- color: #007bff; /* Blue color for hyperlinks */
476
- }
477
- """,
478
- cache_examples = False,
479
- )
480
-
481
- # Add Javascript to update HTML
482
- interface.load = """
483
  function(downloaded_dois, failed_dois){
484
  let downloaded_html = '<ul>';
485
  downloaded_dois.split('\\n').filter(Boolean).forEach(doi => {
@@ -497,12 +485,14 @@ def create_gradio_interface():
497
  return [downloaded_html, failed_html];
498
 
499
  }
500
- """
501
-
502
- # Add the report button
503
- with gr.Row():
504
- report_button = gr.Button("Create Report")
505
- report_output = gr.File(label="Download Report")
 
 
506
  report_button.click(create_report, inputs = [downloaded_dois_html,failed_dois_html], outputs=report_output)
507
 
508
  return interface
 
414
  return report_path
415
  return None
416
 
417
+
 
418
  downloaded_dois_html = gr.HTML(label="""
419
  <div style='padding-bottom: 5px; font-weight: bold;'>
420
  Enter Single DOI
 
434
  <div id="failed-dois"></div>
435
  </div>
436
  """)
437
+
438
+ with gr.Blocks(theme="Hev832/Applio") as interface:
439
+ gr.Markdown("""# 🔬 Academic Paper Batch Downloader""")
440
+ gr.Markdown("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.")
441
+ with gr.Row():
442
+ with gr.Column():
443
+ bib_file_input = gr.File(file_types=['.bib'], label="Upload BibTeX File")
444
+ doi_input = gr.Textbox(label="Enter Single DOI", placeholder="10.xxxx/xxxx")
445
+ dois_input = gr.Textbox(label="Enter Multiple DOIs (one per line)", placeholder="10.xxxx/xxxx\n10.yyyy/yyyy\n...")
446
+
447
+ with gr.Row():
448
+ clear_button = gr.Button("Clear")
449
+ submit_button = gr.Button("Submit")
450
+
451
+ with gr.Accordion("Examples"):
452
+ gr.Examples(
453
+ examples=[
454
+ ["example.bib", None, None], # Bibtex File
455
+ [None, "10.1038/nature12373", None], # Single DOI
456
+ [None, None, "10.1109/5.771073\n10.3390/horticulturae8080677"], # Multiple DOIs
457
+ ],
458
+ inputs=[bib_file_input, doi_input, dois_input]
459
+ )
460
+
461
+ with gr.Column():
462
+ file_output = gr.File(label="Download Papers (ZIP) or Single PDF")
463
+ downloaded_dois_html
464
+ failed_dois_html
465
+ single_pdf_output = gr.File(label="Downloaded Single PDF")
466
+ with gr.Row():
467
+ report_button = gr.Button("Create Report")
468
+ report_output = gr.File(label="Download Report")
469
+
470
+ interface.load = """
 
 
 
 
 
 
 
 
 
 
 
471
  function(downloaded_dois, failed_dois){
472
  let downloaded_html = '<ul>';
473
  downloaded_dois.split('\\n').filter(Boolean).forEach(doi => {
 
485
  return [downloaded_html, failed_html];
486
 
487
  }
488
+ """
489
+
490
+ submit_button.click(
491
+ download_papers,
492
+ inputs=[bib_file_input, doi_input, dois_input],
493
+ outputs=[file_output, downloaded_dois_html, failed_dois_html, single_pdf_output],
494
+ )
495
+
496
  report_button.click(create_report, inputs = [downloaded_dois_html,failed_dois_html], outputs=report_output)
497
 
498
  return interface