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()