Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update optional dependencies #612

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🎨 fix linting
  • Loading branch information
ajndkr committed Mar 5, 2023
commit 6811a824781d5330d685c0867e48659c80fc7432
3 changes: 2 additions & 1 deletion gpt_index/readers/file/docs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def parse_file(self, file: Path, errors: str = "ignore") -> str:
import docx2txt
except ImportError:
raise ImportError(
"docx2txt is required to read Microsoft Word files: `pip install docx2txt`"
"docx2txt is required to read Microsoft Word files: "
"`pip install docx2txt`"
)

text = docx2txt.process(file)
Expand Down
12 changes: 8 additions & 4 deletions gpt_index/readers/file/image_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@ def _init_parser(self) -> Dict:
try:
import torch # noqa: F401
except ImportError:
raise ImportError("install pytorch to use the model: `pip install torch`")
raise ImportError(
"install pytorch to use the model: " "`pip install torch`"
)
try:
from transformers import DonutProcessor, VisionEncoderDecoderModel
except ImportError:
raise ImportError(
"transformers is required for using DONUT model: `pip install transformers`"
"transformers is required for using DONUT model: "
"`pip install transformers`"
)
try:
import sentencepiece # noqa: F401
except ImportError:
raise ImportError(
"sentencepiece is required for using DONUT model: `pip install sentencepiece`"
"sentencepiece is required for using DONUT model: "
"`pip install sentencepiece`"
)
try:
from PIL import Image # noqa: F401
except ImportError:
raise ImportError(
"PIL is required to read image files: `pip install Pillow`"
"PIL is required to read image files: " "`pip install Pillow`"
)

processor = DonutProcessor.from_pretrained(
Expand Down
11 changes: 7 additions & 4 deletions gpt_index/readers/file/slides_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ def _init_parser(self) -> Dict:
from pptx import Presentation # noqa: F401
except ImportError:
raise ImportError(
"The package `python-pptx` is required to read Powerpoint files: `pip install python-pptx`"
"The package `python-pptx` is required to read Powerpoint files: "
"`pip install python-pptx`"
)
try:
import torch # noqa: F401
except ImportError:
raise ImportError(
"The package `pytorch` is required to caption images: `pip install torch`"
"The package `pytorch` is required to caption images: "
"`pip install torch`"
)
try:
from transformers import (
Expand All @@ -40,13 +42,14 @@ def _init_parser(self) -> Dict:
)
except ImportError:
raise ImportError(
"The package `transformers` is required to caption images: `pip install transformers`"
"The package `transformers` is required to caption images: "
"`pip install transformers`"
)
try:
from PIL import Image # noqa: F401
except ImportError:
raise ImportError(
"PIL is required to read image files: `pip install Pillow`"
"PIL is required to read image files: " "`pip install Pillow`"
)

model = VisionEncoderDecoderModel.from_pretrained(
Expand Down
3 changes: 2 additions & 1 deletion gpt_index/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def tokenizer(self) -> Callable[[str], List]:
import transformers
except ImportError:
raise ImportError(
"`transformers` package not found, please run `pip install transformers`"
"`transformers` package not found, "
"please run `pip install transformers`"
)

tokenizer = transformers.GPT2TokenizerFast.from_pretrained("gpt2")
Expand Down