Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -436,10 +436,10 @@ class PaperDownloader:
|
|
436 |
with open(filepath, 'wb') as f:
|
437 |
f.write(pdf_content)
|
438 |
logger.info(f"Successfully downloaded: {filename}")
|
439 |
-
return filepath, f'<a href="https://doi.org/{doi}">{doi}</a>', ""
|
440 |
else:
|
441 |
logger.warning(f"Could not download: {doi}")
|
442 |
-
return None, f"Could not download {doi}", f'<a href="https://doi.org/{doi}">{doi}</a>'
|
443 |
|
444 |
except Exception as e:
|
445 |
logger.error(f"Error processing {doi}: {e}")
|
@@ -465,10 +465,10 @@ class PaperDownloader:
|
|
465 |
filepath_unique = os.path.join(self.output_dir, filename)
|
466 |
os.rename(filepath, filepath_unique)
|
467 |
downloaded_files.append(filepath_unique)
|
468 |
-
downloaded_links.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
469 |
|
470 |
else:
|
471 |
-
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
472 |
|
473 |
if downloaded_files:
|
474 |
zip_filename = 'papers.zip'
|
@@ -522,13 +522,13 @@ class PaperDownloader:
|
|
522 |
f.write(pdf_content)
|
523 |
|
524 |
downloaded_files.append(filepath)
|
525 |
-
downloaded_links.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
526 |
logger.info(f"Successfully downloaded: {filename}")
|
527 |
else:
|
528 |
-
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
529 |
|
530 |
except Exception as e:
|
531 |
-
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
532 |
logger.error(f"Error processing {doi}: {e}")
|
533 |
|
534 |
# Create ZIP of downloaded papers
|
@@ -584,13 +584,13 @@ class PaperDownloader:
|
|
584 |
f.write(pdf_content)
|
585 |
|
586 |
downloaded_files.append(filepath)
|
587 |
-
downloaded_links.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
588 |
logger.info(f"Successfully downloaded: {filename}")
|
589 |
else:
|
590 |
-
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
591 |
|
592 |
except Exception as e:
|
593 |
-
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
594 |
logger.error(f"Error processing {doi}: {e}")
|
595 |
|
596 |
# Create ZIP of downloaded papers
|
@@ -682,20 +682,41 @@ def create_gradio_interface():
|
|
682 |
|
683 |
# Add Javascript to update HTML
|
684 |
interface.load = """
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
695 |
});
|
696 |
-
document.querySelector("#failed-dois").innerHTML = failed_html;
|
697 |
-
return [downloaded_html, failed_html];
|
698 |
}
|
|
|
699 |
"""
|
700 |
return interface
|
701 |
|
|
|
436 |
with open(filepath, 'wb') as f:
|
437 |
f.write(pdf_content)
|
438 |
logger.info(f"Successfully downloaded: {filename}")
|
439 |
+
return filepath, f'<div style="display: flex; align-items: center;">✓ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>', ""
|
440 |
else:
|
441 |
logger.warning(f"Could not download: {doi}")
|
442 |
+
return None, f"Could not download {doi}", f'<div style="display: flex; align-items: center;">❌ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>'
|
443 |
|
444 |
except Exception as e:
|
445 |
logger.error(f"Error processing {doi}: {e}")
|
|
|
465 |
filepath_unique = os.path.join(self.output_dir, filename)
|
466 |
os.rename(filepath, filepath_unique)
|
467 |
downloaded_files.append(filepath_unique)
|
468 |
+
downloaded_links.append(f'<div style="display: flex; align-items: center;">✓ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
469 |
|
470 |
else:
|
471 |
+
failed_dois.append(f'<div style="display: flex; align-items: center;">❌ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
472 |
|
473 |
if downloaded_files:
|
474 |
zip_filename = 'papers.zip'
|
|
|
522 |
f.write(pdf_content)
|
523 |
|
524 |
downloaded_files.append(filepath)
|
525 |
+
downloaded_links.append(f'<div style="display: flex; align-items: center;">✓ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
526 |
logger.info(f"Successfully downloaded: {filename}")
|
527 |
else:
|
528 |
+
failed_dois.append(f'<div style="display: flex; align-items: center;">❌ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
529 |
|
530 |
except Exception as e:
|
531 |
+
failed_dois.append(f'<div style="display: flex; align-items: center;">❌ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
532 |
logger.error(f"Error processing {doi}: {e}")
|
533 |
|
534 |
# Create ZIP of downloaded papers
|
|
|
584 |
f.write(pdf_content)
|
585 |
|
586 |
downloaded_files.append(filepath)
|
587 |
+
downloaded_links.append(f'<div style="display: flex; align-items: center;">✓ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
588 |
logger.info(f"Successfully downloaded: {filename}")
|
589 |
else:
|
590 |
+
failed_dois.append(f'<div style="display: flex; align-items: center;">❌ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
591 |
|
592 |
except Exception as e:
|
593 |
+
failed_dois.append(f'<div style="display: flex; align-items: center;">❌ <a href="https://doi.org/{doi}">{doi}</a> <button onclick="copyLink(this)">Copy</button></div>')
|
594 |
logger.error(f"Error processing {doi}: {e}")
|
595 |
|
596 |
# Create ZIP of downloaded papers
|
|
|
682 |
|
683 |
# Add Javascript to update HTML
|
684 |
interface.load = """
|
685 |
+
function(downloaded_dois, failed_dois) {
|
686 |
+
let downloaded_html = '';
|
687 |
+
downloaded_dois.split('\\n').filter(Boolean).forEach(doi => {
|
688 |
+
downloaded_html += doi + '<br>';
|
689 |
+
});
|
690 |
+
document.querySelector("#downloaded-dois").innerHTML = downloaded_html;
|
691 |
+
|
692 |
+
let failed_html = '';
|
693 |
+
failed_dois.split('\\n').filter(Boolean).forEach(doi => {
|
694 |
+
failed_html += doi + '<br>';
|
695 |
+
});
|
696 |
+
document.querySelector("#failed-dois").innerHTML = failed_html;
|
697 |
+
return [downloaded_html, failed_html];
|
698 |
+
}
|
699 |
+
"""
|
700 |
+
|
701 |
+
interface.head = """
|
702 |
+
<script>
|
703 |
+
function copyLink(button) {
|
704 |
+
const linkElement = button.previousElementSibling;
|
705 |
+
const link = linkElement.href;
|
706 |
+
navigator.clipboard.writeText(link)
|
707 |
+
.then(() => {
|
708 |
+
button.innerText = '✓ Copied';
|
709 |
+
button.style.color = 'green';
|
710 |
+
setTimeout(() => {
|
711 |
+
button.innerText = 'Copy';
|
712 |
+
button.style.color = '';
|
713 |
+
}, 2000);
|
714 |
+
})
|
715 |
+
.catch(err => {
|
716 |
+
console.error('Failed to copy link: ', err);
|
717 |
});
|
|
|
|
|
718 |
}
|
719 |
+
</script>
|
720 |
"""
|
721 |
return interface
|
722 |
|