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
uvif you don't have it already:curl -LsSf https://astral.sh/uv/install.sh | sh -
Sync the dependencies:
uv sync
Run the server in development mode with auto-reload:
uv run fastapi dev app/main.pyIf you're using environment variables:
uv run dotenv run fastapi dev app/main.pyRun the server in production mode:
uv run fastapi run app/main.pyIf 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_imagesdirectory.
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/extractMake 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_imagesdirectory)
