LLM-PDF-Parser is a FastAPI-based application that extracts text from PDFs and images and uses Ollama's LLM to extract specific fields based on a given JSON template. 🚀
- 📝 Extract text from PDFs and images (JPG, PNG, JPEG) using PyMuPDF and EasyOCR.
- 🤖 Leverage AI to extract structured data based on a provided JSON template.
- ⚡ FastAPI backend for quick and easy integration.
- 🔥 Supports OCR when text extraction from PDFs is insufficient.
- 🔄 Cross-Origin Resource Sharing (CORS) enabled for flexible frontend integration.
git clone https://github.com/RiccardoTOTI/LLM-PDF-Extractor.git
cd LLM-PDF-Parser
pip install -r requirements.txt
Create a .env
file and configure the following variables (or set them in your environment):
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=iodose/nuextract-v1.5
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
ollama run iodose/nuextract-v1.5
You can also run the application using Docker.
- Build the Docker image:
docker build -t llm-pdf-parser .
- Run the container:
docker run -p 8000:8000 llm-pdf-parser
You can use Docker Compose to spin up both the application and Ollama:
- Run the services:
docker-compose up -d
- Download the model using the script inside
tools
directory in the Ollama Container:docker exec -it ollama .tools/download_model.sh iodose/nuextract-v1.5
Endpoint: POST /extract
Request:
curl -X 'POST' \
'http://localhost:8000/extract' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@yourfile.pdf' \
-F 'fields={"Patient":{"First Name":"","Last Name":"","Tax Code":"","Doctor":[]}}
'
Response Example:
{
"extracted_data": {
"Patient": {
"First Name": "John",
"Last Name": "Doe",
"Tax Code": "ABC123XYZ",
"Doctor": [ #support list of elements
"Dr. Smith",
"Dr. Bean"
]
}
}
}
- Uploads a PDF or Image via FastAPI.
- Extracts text using PyMuPDF or EasyOCR (for scanned documents/images).
- Sends extracted text to Ollama's LLM, which structures it based on the provided JSON template.
- Returns extracted structured data as a JSON response. ✅
- Python 🐍
- FastAPI ⚡
- PyMuPDF 📄
- EasyOCR 🔍
- Ollama LLM 🤖
- Uvicorn 🚀
Contributions are welcome! Feel free to submit issues or open a pull request. 😊
This project is licensed under the Apache 2.0 License.
💡 Have suggestions or need help? Open an issue or reach out! 🚀