This project provides a FastAPI backend for transforming PDFs into images for the purposes of structured data extraction via BAML. It includes a Streamlit frontend for easy interaction and usage.
- FastAPI Backend - REST API for processing PDFs into images
- Streamlit Frontend - User-friendly web interface for file uploads and results
- PDF Processing - Converts PDFs to images for analysis
- BAML Integration - Generate a concise summary of the PDF document that was transformed into images
-
Install
uv
if you don't have it already:curl -LsSf https://astral.sh/uv/install.sh | sh
-
Create and activate a virtual environment:
uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
uv pip install -r requirements.txt
Run the server in development mode with auto-reload:
uv run fastapi dev app/main.py
If you're using environment variables:
uv run dotenv run fastapi dev app/main.py
Run the server in production mode:
uv run fastapi run app/main.py
If you want to run the FastAPI server in production, you can use Docker.
-
Build the Docker image:
docker build -t fastapi-app .
-
Run the container:
docker run -p 8000:8000 fastapi-app
-
For production with environment variables:
docker run -p 8000:8000 --env-file .env fastapi-app
-
Make sure the FastAPI server is running first.
-
Run the Streamlit app:
streamlit run streamlit_app.py
-
Open your browser to the URL provided by Streamlit (usually http://localhost:8501).
-
Upload a PDF or image file, click "Extract Data", and view the results.
-
Extracted images will be saved to the
extracted_images
directory.
You can test the API endpoint using curl:
curl -X POST -H "Content-Type: multipart/form-data" -F "file=@files/images/invoice.png" http://localhost:8000/extract
Make sure the file path (files/images/invoice.png
) points to an existing file on your system.
The following endpoints are available:
GET /
: Information about the APIPOST /extract
: Upload a PDF or image file to extract data using BAML
Add more endpoints that use BAML to extract structured data from the images as necessary.
- Run the FastAPI server in development mode
uv run fastapi dev app/main.py
- Run the Streamlit app
streamlit run streamlit_app.py
- Open your browser to the URL provided by Streamlit (usually http://localhost:8501)
- Upload a PDF or image file, click "Extract Data", and view the summary of the document
and a preview of the extracted images (the images are saved to the
extracted_images
directory)