Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
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 |
-
|
381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
)
|
394 |
|
395 |
-
return interface
|
396 |
-
|
397 |
# Add Javascript to update HTML
|
398 |
interface.load = """
|
399 |
function(downloaded_dois, failed_dois){
|
400 |
-
|
401 |
-
|
402 |
-
downloaded_html +=
|
403 |
});
|
404 |
-
downloaded_html +=
|
405 |
document.querySelector("#downloaded-dois").innerHTML = downloaded_html;
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
failed_html += '<li
|
410 |
});
|
411 |
-
|
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
|