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

added README note on poppler install and better error handling for po… #9

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 15 additions & 5 deletions elm/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,22 @@ def clean_poppler(self, layout=True):
if not os.path.exists(os.path.dirname(fp_out)):
os.makedirs(os.path.dirname(fp_out), exist_ok=True)

stdout = subprocess.run(args, check=True, stdout=subprocess.PIPE)
if stdout.returncode != 0:
msg = ('Poppler raised return code {}: {}'
.format(stdout.returncode, stdout))
try:
stdout = subprocess.run(args, check=True,
stdout=subprocess.PIPE)
except Exception as e:
msg = ('PDF cleaning with poppler failed! This usually '
'because you have not installed the poppler utility '
'(see https://poppler.freedesktop.org/). '
f'Full error: {e}')
logger.exception(msg)
raise RuntimeError(msg)
raise RuntimeError(msg) from e
else:
if stdout.returncode != 0:
msg = ('Poppler raised return code {}: {}'
.format(stdout.returncode, stdout))
logger.exception(msg)
raise RuntimeError(msg)

with open(fp_out, 'r') as f:
clean_txt = f.read()
Expand Down
2 changes: 2 additions & 0 deletions examples/energy_wizard/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ corpus.

Notes:

- In this example, we use the optional `popper <https://poppler.freedesktop.org/>`_ PDF utility which you will have to install separately. You can also use the python-native ``PyPDF2`` package when calling using ``elm.pdf.PDFtoTXT`` but we have found that poppler works better.

- Streamlit is required to run this app, which is not an explicit requirement of this repo (``pip install streamlit``)

- You need to set up your own OpenAI or Azure-OpenAI API keys to run the scripts.
Expand Down
Loading