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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -47
app.py CHANGED
@@ -336,36 +336,25 @@ class PaperDownloader:
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,40 +366,73 @@ def create_gradio_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){
400
- let downloaded_html = '<ul style="list-style-type: none; padding: 0; margin: 0;">';
401
- downloaded_dois.split('\\n').filter(Boolean).forEach(doi => {
402
- downloaded_html += '<li style="margin-bottom: 5px; padding: 5px; background-color: #e6f3e6; border-radius: 3px;">' + doi + '</li>';
403
  });
404
- downloaded_html += '</ul>';
405
  document.querySelector("#downloaded-dois").innerHTML = downloaded_html;
406
-
407
- let failed_html = '<ul style="list-style-type: none; padding: 0; margin: 0;">';
408
- failed_dois.split('\\n').filter(Boolean).forEach(doi => {
409
- failed_html += '<li style="margin-bottom: 5px; padding: 5px; background-color: #f2dede; border-radius: 3px;">' + doi + '</li>';
410
  });
411
- failed_html += '</ul>';
412
  document.querySelector("#failed-dois").innerHTML = failed_html;
413
  return [downloaded_html, failed_html];
 
414
  }
415
  """
416
  return interface
 
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
  ],
367
  outputs=[
368
  gr.File(label="Download Papers (ZIP) or Single PDF"),
369
+ gr.HTML(label="""
370
+ <div style='padding-bottom: 5px; font-weight: bold;'>
371
+ Enter Single DOI
372
+ </div>
373
+ <div style='border: 1px solid #ddd; padding: 5px; border-radius: 5px;'>
374
+ <div style='padding-bottom: 5px; font-weight: bold;'>
375
+ Downloaded DOIs
376
+ </div>
377
+ <div id="downloaded-dois"></div>
378
+ </div>
379
+ """),
380
+ gr.HTML(label="""
381
+ <div style='border: 1px solid #ddd; padding: 5px; border-radius: 5px;'>
382
+ <div style='padding-bottom: 5px; font-weight: bold;'>
383
+ Failed DOIs
384
+ </div>
385
+ <div id="failed-dois"></div>
386
+ </div>
387
+ """),
388
  gr.File(label="Downloaded Single PDF")
389
  ],
390
  title="🔬 Academic Paper Batch Downloader",
391
  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.",
392
  theme="Hev832/Applio",
393
  examples=[
394
+ ["example.bib", None, None], # Bibtex File
395
+ [None, "10.1038/nature12373", None], # Single DOI
396
+ [None, None, "10.1109/5.771073\n10.3390/horticulturae8080677"], # Multiple DOIs
397
+ ],
398
+ css="""
399
+ .gradio-container {
400
+ background-color: #222222;
401
+ }
402
+ .gr-interface {
403
+ max-width: 800px;
404
+ margin: 0 auto;
405
+ }
406
+ .gr-box {
407
+ background-color: white;
408
+ border-radius: 10px;
409
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
410
+ }
411
+ .output-text a {
412
+ color: #007bff; /* Blue color for hyperlinks */
413
+ }
414
+ """,
415
+ cache_examples = False,
416
  )
417
 
 
 
418
  # Add Javascript to update HTML
419
  interface.load = """
420
  function(downloaded_dois, failed_dois){
421
+ let downloaded_html = '<ul>';
422
+ downloaded_dois.split('\\n').filter(Boolean).forEach(doi => {
423
+ downloaded_html += '<li>' + doi + '</li>';
424
  });
425
+ downloaded_html += '</ul>';
426
  document.querySelector("#downloaded-dois").innerHTML = downloaded_html;
427
+
428
+ let failed_html = '<ul>';
429
+ failed_dois.split('\\n').filter(Boolean).forEach(doi => {
430
+ failed_html += '<li>' + doi + '</li>';
431
  });
432
+ failed_html += '</ul>';
433
  document.querySelector("#failed-dois").innerHTML = failed_html;
434
  return [downloaded_html, failed_html];
435
+
436
  }
437
  """
438
  return interface