Skip to content

Commit

Permalink
Move imports inside function and update decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Jan 22, 2025
1 parent fe5b0a7 commit 17a42e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@


from ......coding.func_with_reqs import with_requirements
from ......import_utils import optional_import_block

with optional_import_block():
import arxiv


@with_requirements(["arxiv"], ["arxiv"])
@with_requirements(["arxiv"])
def arxiv_download(id_list: list, download_dir="./"):
"""Downloads PDF files from ArXiv based on a list of arxiv paper IDs.
Expand All @@ -21,6 +17,8 @@ def arxiv_download(id_list: list, download_dir="./"):
Returns:
list: A list of paths to the downloaded PDF files.
"""
import arxiv

paths = []
for paper in arxiv.Client().results(arxiv.Search(id_list=id_list)):
path = paper.download_pdf(download_dir, filename=paper.get_short_id() + ".pdf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@


from ......coding.func_with_reqs import with_requirements
from ......import_utils import optional_import_block

with optional_import_block():
import arxiv


@with_requirements(["arxiv"], ["arxiv"])
@with_requirements(["arxiv"])
def arxiv_search(query, max_results=10, sortby="relevance"):
"""Search for articles on arXiv based on the given query.
Expand All @@ -28,6 +24,7 @@ def arxiv_search(query, max_results=10, sortby="relevance"):
- 'doi': The DOI of the article (If applicable).
- 'published': The publication date of the article in the format 'Y-M'.
"""
import arxiv

def get_author(r):
return ", ".join(a.name for a in r.authors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
import os

from ......coding.func_with_reqs import with_requirements
from ......import_utils import optional_import_block

with optional_import_block():
from PIL import Image


@with_requirements(["transformers", "torch"], ["transformers", "torch", "PIL", "os"])
@with_requirements(["transformers", "torch", "PIL"], ["transformers", "torch", "os"])
def image_qa(image, question, ckpt="Salesforce/blip-vqa-base"):
"""Perform question answering on an image using a pre-trained VQA model.
Expand All @@ -22,6 +18,7 @@ def image_qa(image, question, ckpt="Salesforce/blip-vqa-base"):
dict: The generated answer text.
"""
import torch
from PIL import Image
from transformers import BlipForQuestionAnswering, BlipProcessor

def image_processing(img):
Expand Down

0 comments on commit 17a42e4

Please sign in to comment.