Code samples
Query processed PDF with HuggingChat
This example uses the Unstructured Ingest Python library or the Unstructured JavaScript/TypeScript SDK to send a PDF file to Unstructured API services for processing. Unstructured processes the PDF and extracts the PDF’s content. This example then sends some of the content to HuggingChat, Hugging Face’s open-source AI chatbot, along with some queries about this content.
To run this example, you’ll need:
- The hugchat package for Python, or the huggingface-chat package for JavaScript/TypeScript.
- Your Unstructured API key and API URL. Get an API key and API URL.
- Your Hugging Face account’s email address and account password. Get an account.
- A PDF file for Unstructured to process. This example uses a sample PDF file containing the text of the United States Constitution, available for download from https://constitutioncenter.org/media/files/constitution.pdf.
These environment variables:
UNSTRUCTURED_API_KEY
- Your Unstructured API key value.UNSTRUCTURED_API_URL
- Your Unstructured API URL.
These environment variables:
HUGGING_FACE_EMAIL
, representing your Hugging Face account’s email address.HUGGING_FACE_PASSWORD
, representing your Hugging Face account’s email address.HUGGING_FACE_COOKIE_DIR_PATH
, representing a login cookie cache path, typically./cookies/
or./login_cache/
.
This example’s code is as follows:
Was this page helpful?