|
|
import gradio as gr |
|
|
from scidownl import scihub_download |
|
|
import os |
|
|
|
|
|
def download_paper(doi): |
|
|
""" |
|
|
Function to download a paper using a DOI. |
|
|
The paper will be saved in the ./papers/ directory. |
|
|
""" |
|
|
try: |
|
|
paper_type = "doi" |
|
|
output_dir = "./papers/" |
|
|
os.makedirs(output_dir, exist_ok=True) |
|
|
output_path = os.path.join(output_dir, f"{doi.replace('/', '_')}.pdf") |
|
|
scihub_download(doi, paper_type=paper_type, out=output_path) |
|
|
if os.path.exists(output_path): |
|
|
|
|
|
return gr.File.update(value=output_path, visible=True) |
|
|
else: |
|
|
return gr.File.update(value=None, visible=False), "Failed to download the paper. Please check the DOI or try again later." |
|
|
except Exception as e: |
|
|
return gr.File.update(value=None, visible=False), f"An error occurred: {str(e)}" |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=download_paper, |
|
|
inputs=gr.Textbox(label="Enter DOI", placeholder="e.g., 10.1145/3375633"), |
|
|
outputs=[ |
|
|
gr.File(label="Downloaded Paper"), |
|
|
gr.Textbox(label="Download Status") |
|
|
], |
|
|
title="Paper Downloader", |
|
|
description="Enter a DOI to download a research paper.", |
|
|
theme=gr.themes.Soft(), |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
iface.launch() |