C2MV commited on
Commit
2e7d59c
·
verified ·
1 Parent(s): b041176

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -56
app.py CHANGED
@@ -336,25 +336,36 @@ class PaperDownloader:
336
 
337
  def create_gradio_interface():
338
  """Create Gradio interface for Paper Downloader"""
339
- downloader = PaperDownloader()
340
-
341
  def download_papers(bib_file, doi_input, dois_input):
342
- if bib_file:
343
- # Check file type
344
- if not bib_file.name.lower().endswith('.bib'):
345
- return None, "Error: Please upload a .bib file", "Error: Please upload a .bib file", None
346
-
347
- zip_path, downloaded_dois, failed_dois, _ = downloader.process_bibtex(bib_file)
348
- return zip_path, downloaded_dois, failed_dois, None
349
- elif doi_input:
350
- filepath, message, failed_doi = downloader.download_single_doi(doi_input)
351
- return None, message, failed_doi, filepath
352
- elif dois_input:
353
- zip_path, downloaded_dois, failed_dois = downloader.download_multiple_dois(dois_input)
354
- return zip_path, downloaded_dois, failed_dois, None
355
- else:
356
- 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
357
-
 
 
 
 
 
 
 
 
 
 
 
 
 
358
 
359
  # Gradio Interface
360
  interface = gr.Interface(
@@ -366,52 +377,23 @@ def create_gradio_interface():
366
  ],
367
  outputs=[
368
  gr.File(label="Download Papers (ZIP) or Single PDF"),
369
- gr.HTML(label="""
370
- <div style='padding: 10px; background-color: #f0f0f0; border-radius: 8px;'>
371
- <h3 style='color: #2c8f2c; margin-bottom: 10px;'>📥 Found DOIs</h3>
372
- <div style='border: 1px solid #2c8f2c; padding: 10px; border-radius: 5px; background-color: white;'>
373
- <div id="downloaded-dois" style='max-height: 200px; overflow-y: auto;'></div>
374
- </div>
375
- </div>
376
- """),
377
- gr.HTML(label="""
378
- <div style='padding: 10px; background-color: #f0f0f0; border-radius: 8px;'>
379
- <h3 style='color: #d9534f; margin-bottom: 10px;'>❌ Missed DOIs</h3>
380
- <div style='border: 1px solid #d9534f; padding: 10px; border-radius: 5px; background-color: white;'>
381
- <div id="failed-dois" style='max-height: 200px; overflow-y: auto;'></div>
382
- </div>
383
- </div>
384
- """),
385
  gr.File(label="Downloaded Single PDF")
386
  ],
387
  title="🔬 Academic Paper Batch Downloader",
388
  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.",
389
  theme="Hev832/Applio",
390
  examples=[
391
- ["example.bib", None, None], # Bibtex File
392
- [None, "10.1038/nature12373", None], # Single DOI
393
- [None, None, "10.1109/5.771073\n10.3390/horticulturae8080677"], # Multiple DOIs
394
- ],
395
- css="""
396
- .gradio-container {
397
- background-color: #222222;
398
- }
399
- .gr-interface {
400
- max-width: 800px;
401
- margin: 0 auto;
402
- }
403
- .gr-box {
404
- background-color: white;
405
- border-radius: 10px;
406
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
407
- }
408
- .output-text a {
409
- color: #007bff; /* Blue color for hyperlinks */
410
- }
411
- """,
412
- cache_examples = False,
413
  )
414
 
 
 
415
  # Add Javascript to update HTML
416
  interface.load = """
417
  function(downloaded_dois, failed_dois){
 
336
 
337
  def create_gradio_interface():
338
  """Create Gradio interface for Paper Downloader"""
 
 
339
  def download_papers(bib_file, doi_input, dois_input):
340
+ # Your existing download_papers function implementation
341
+
342
+ # Update the HTML labels
343
+ downloaded_dois_html = ""
344
+ failed_dois_html = ""
345
+
346
+ # Build the HTML for Found DOIs
347
+ if downloaded_dois:
348
+ downloaded_dois_html = """
349
+ <div class="found-dois-container">
350
+ <div class="found-dois-header">📥 Found DOIs</div>
351
+ <div class="found-dois-list">
352
+ {}
353
+ </div>
354
+ </div>
355
+ """.format("\n".join([f'<a href="https://doi.org/{doi}" class="doi-link found-doi-link">{doi}</a>' for doi in downloaded_dois.split("\n") if doi]))
356
+
357
+ # Build the HTML for Missed DOIs
358
+ if failed_dois:
359
+ failed_dois_html = """
360
+ <div class="missed-dois-container">
361
+ <div class="missed-dois-header">❌ Missed DOIs</div>
362
+ <div class="missed-dois-list">
363
+ {}
364
+ </div>
365
+ </div>
366
+ """.format("\n".join([f'<a href="https://doi.org/{doi}" class="doi-link missed-doi-link">{doi}</a>' for doi in failed_dois.split("\n") if doi]))
367
+
368
+ return zip_path, downloaded_dois_html, failed_dois_html, filepath
369
 
370
  # Gradio Interface
371
  interface = gr.Interface(
 
377
  ],
378
  outputs=[
379
  gr.File(label="Download Papers (ZIP) or Single PDF"),
380
+ gr.HTML(label=downloaded_dois_html),
381
+ gr.HTML(label=failed_dois_html),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  gr.File(label="Downloaded Single PDF")
383
  ],
384
  title="🔬 Academic Paper Batch Downloader",
385
  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.",
386
  theme="Hev832/Applio",
387
  examples=[
388
+ ["example.bib", None, None],
389
+ [None, "10.1038/nature12373", None],
390
+ [None, None, "10.1109/5.771073\n10.3390/horticulturae8080677"]
391
+ ],
392
+ cache_examples=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  )
394
 
395
+ return interface
396
+
397
  # Add Javascript to update HTML
398
  interface.load = """
399
  function(downloaded_dois, failed_dois){