File size: 1,400 Bytes
157cb89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b8519c
 
157cb89
0b8519c
157cb89
0b8519c
157cb89
 
 
 
 
0b8519c
 
 
 
157cb89
0b8519c
 
157cb89
 
 
0b8519c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)  # Ensure the directory exists
        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):
            # Create a downloadable link
            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)}"

# Gradio app interface
iface = gr.Interface(
    fn=download_paper,
    inputs=gr.Textbox(label="Enter DOI", placeholder="e.g., 10.1145/3375633"),
    outputs=[
        gr.File(label="Downloaded Paper"),  # Output for the downloadable link
        gr.Textbox(label="Download Status")
    ],
    title="Paper Downloader",
    description="Enter a DOI to download a research paper.",
    theme=gr.themes.Soft(),  # Use a pretty theme
)

if __name__ == "__main__":
    iface.launch()