yoshidashingo / langchain-book

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

212P 8.7章 ベクトル化時エラー発生

yushi-sim opened this issue · comments

エラーの説明

212P 9番「PDFファイルのテキスト分割とベクトル化」の下記コマンドの実行時にエラーが発生しました
コマンド:python add_document.py ai-guideline.pdf

該当のログの全量

ec2-user:~/environment/streamlit-langchain-app11 (main) $ sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Last metadata expiration check: 0:34:33 ago on Sat Aug  3 04:28:40 2024.
[MIRROR] epel-release-latest-7.noarch.rpm: Status code: 404 for https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm (IP: 38.145.60.22)
[MIRROR] epel-release-latest-7.noarch.rpm: Status code: 404 for https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm (IP: 38.145.60.22)
[MIRROR] epel-release-latest-7.noarch.rpm: Status code: 404 for https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm (IP: 38.145.60.22)
[MIRROR] epel-release-latest-7.noarch.rpm: Status code: 404 for https://dl.fedoraproject.org/pub/epel/epel-release-laPython-dotenv could not parse statement starting at line 14
Traceback (most recent call last):  File "/home/ec2-user/environment/streamlit-langchain-app11/add_document.py", line 34, in <module>
    raw_docs = loader.load()
  File "/home/ec2-user/.local/lib/python3.9/site-packages/langchain/document_loaders/unstructured.py", line 86, in load
    elements = self._get_elements()
  File "/home/ec2-user/.local/lib/python3.9/site-packages/langchain/document_loaders/pdf.py", line 59, in _get_elements
    return partition_pdf(filename=self.file_path, **self.unstructured_kwargs)
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured/documents/elements.py", line 242, in wrapper
    elements = func(*args, **kwargs)
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured/file_utils/filetype.py", line 541, in wrapper    elements = func(*args, **kwargs)
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured/chunking/title.py", line 197, in wrapper    elements = func(*args, **kwargs)
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured/partition/pdf.py", line 130, in partition_pdf
    return partition_pdf_or_image(
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured/partition/pdf.py", line 277, in partition_pdf_or_image    return _partition_pdf_or_image_with_ocr(
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured/utils.py", line 43, in wrapper
    return func(*args, **kwargs)
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured/partition/pdf.py", line 716, in _partition_pdf_or_image_with_ocr
    _text, _bboxes = unstructured_pytesseract.run_and_get_multiple_output(
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured_pytesseract/pytesseract.py", line 316, in run_and_get_multiple_output
    run_tesseract(**kwargs)
  File "/home/ec2-user/.local/lib/python3.9/site-packages/unstructured_pytesseract/pytesseract.py", line 279, in run_tesseract
    raise TesseractError(proc.returncode, get_errors(error_string))
unstructured_pytesseract.pytesseract.TesseractError: (1, 'Error in pixReadMemTiff: function not present Error in pixReadMem: tiff: no pix returned Error in pixaGenerateFontFromString: pix not made Error in bmfCreate: font pixa not made Error opening data file /usr/share/tesseract/tessdata/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')

質問内容:
Tesseractが英語の言語データを読み込めていないため、上記のエラーが出力されてます。
インストールを試みましたが上手くできません。
また書籍を読んでもインストールする手順が記載されていなかったと思います。
こちらについて、対応方法が分かりましたらご教授お願いしたいです。

環境
AWS Cloud9

申し訳ございません。
理由は分かりませんが、レポジトリーに上がっているコードをコピペして再度実行したところエラーが解消されました。

解決したとのことでよかったです。
もしも解決した理由を確認したい場合は、ご自身で書いたコードとの差分をツールなどで確認してみてください。
差分を確認しても原因が分からないようでしたら、改めて質問いただければこちらでも確認させていただきます。
よろしくお願いします。