This readme contains the code for a web app including a frontend that can be set up as a user facing interface.
To enable you to showcase the power of ColPali and Vespa to your users, and to provide a starting point for your own projects.
"But I only know Python, how can I create a web app that's not Gradio or Streamlit?" 🤔
No worries! This project uses FastHTML to create a beautiful web app - and it's all Python! 🐍
Also, 👇
As a prerequisite, you should run this notebook to prepare the data and deploy the Vespa application.
The following variables are required in your .env file for the application to be able to connect to the Vespa application and the Gemini API:
You can rename the .env.example file to .env and fill in the required values.
The other variables are optional, if you want to use mTLS authentication against the Vespa application.
VESPA_APP_TOKEN_URL=https://abcde.z.vespa-app.cloud
VESPA_CLOUD_SECRET_TOKEN=vespa_cloud_xxxxxxxx
GEMINI_API_KEY=asdfOptionally, set GEMINI_MODEL to use another Gemini model than the default gemini-3.8-flash.
If you want to deploy the application to Huggingface, you also need to set a HF_TOKEN variable, with write permissions.
This is personal, and must be created at huggingface.
HF_TOKEN=hf_xxxxxxxxxxThis application requires Python 3.10 or 3.11. The Hugging Face Space runs Python 3.11.
You can install the dependencies with pip, but we recommend using uv.
Skip to Installing dependencies using uv if you want to use uv.
src/requirements.txt contains the pinned versions used by the Hugging Face Space. It is compiled for Python 3.11:
pip install -r src/requirements.txtWe recommend installing the amazing uv to manage your python environment:
See also installation - uv docs for other installation options.
curl -LsSf https://astral.sh/uv/install.sh | shThen, create a virtual environment:
uv venv Activate the virtual environment:
source .venv/bin/activateSync your virtual environment with the dependencies:
uv sync --extra devTo run the application locally, you can change into the src directory and run:
python main.pyThis will start a local server, and you can access the application at http://localhost:7860.
Before a deploy, make sure to run this to compile the dependencies to requirements.txt if you have made changes to the dependencies:
uv pip compile pyproject.toml --group huggingface --universal --python-version 3.11 -o src/requirements.txtThis will make sure that the dependencies in your pyproject.toml are compiled to the src/requirements.txt file, which is used by the huggingface space.
Run it from this directory, because --group reads the pyproject.toml in the current directory.
The huggingface group contains the Gradio SDK and spaces packages that Hugging Face installs next to requirements.txt, so the pins stay compatible with them.
If you change the Gradio version there, set the same sdk_version in src/README.md.
The command keeps the existing pins where they still satisfy pyproject.toml. To update a package, for example to pick up a security fix, add --upgrade-package <package>.
Note that you need to set HF_TOKEN environment variable first.
This is personal, and must be created at huggingface.
Make sure the token has write access.
Add the Vespa and Gemini variables from your .env as secrets in the Space settings.
Be aware that this will not delete existing files, only modify or add,
see huggingface-cli for more
information.
The src/README.md file contains the configuration for the space.
Feel free to update this file to match your own configuration - name, description, etc.
Note that we can actually use the gradio SDK of spaces, to serve FastHTML apps as well, as long as we serve the app on port 7860.
See Custom python spaces for more information.
To deploy, run from the project root directory:
(Replace vespa-engine/colpali-vespa-visual-retrieval with your own huggingface user/repo name, does not need to exist beforehand)
hf upload vespa-engine/colpali-vespa-visual-retrieval src . --repo-type=space --delete "*" --exclude ".sesskey" --exclude "*__pycache__*" --exclude "static/full_images/**" --exclude "static/sim_maps/**" --commit-message "Deploy to HF Space"Note that we upload only the src directory. The --delete "*" flag ensures that any files that exist in the space but not in your local src directory will be removed, keeping everything in sync.
The --exclude flags keep the local session key, Python caches and cached page images out of the Space.
Hugging Face builds the Space with a single pip command that installs requirements.txt together with the Gradio SDK from sdk_version and the spaces package.
To reproduce that environment and check that the app starts, run from this directory:
python3.11 -m venv /tmp/colpali-hf-test
/tmp/colpali-hf-test/bin/pip install -r src/requirements.txt "gradio[oauth,mcp]==6.29.0" "uvicorn>=0.14.0" "websockets>=10.4" spaces
/tmp/colpali-hf-test/bin/pip check
/tmp/colpali-hf-test/bin/python tests/huggingface_smoke.py --source srcThe smoke test imports the app and requests its pages, with Vespa and the ColPali model mocked.
Add --env-file .env --load-model to also connect to your Vespa application and load the real model (about 6 GB on the first download).
The Verify ColPali dependencies and startup GitHub workflow runs these checks, including --load-model, on pull requests that change this directory.
It also recompiles src/requirements.txt and fails if the result differs from the committed file.
- The Space build fails at
pip installwithResolutionImpossible: a pin insrc/requirements.txtconflicts with what Hugging Face installs next to it (for example,gradio[mcp]limits thepydanticversion). Recompilesrc/requirements.txtas described above, and check thatsdk_versionmatches the Gradio version inpyproject.toml. - Results look unrelated to the query, or the model load prints a
LOAD REPORTwithMISSINGLoRA keys: the installedtransformersversion doesn't load the ColPali adapter for thiscolpali-engineversion.--load-modelin the smoke test checks for this. - Searches return no results: the
pdf_pageschema in your Vespa application is empty. Feed it with the notebook first. Please set the VESPA_APP_MTLS_URL environment variable: withUSE_MTLS=true, the endpoint goes inVESPA_APP_MTLS_URL.- Static files are not found locally: start the app from the
srcdirectory.
This section applies if you want to make changes to the web app.
To add dependencies, you can add them to the pyproject.toml file and compile src/requirements.txt as described in Compiling dependencies.
and then sync the dependencies:
uv sync --extra devTo make changes to output.css apply, run
shad4fast watch # watches all files passed through the tailwind.config.js content section
shad4fast build # minifies the current output.css file to reduce bundle size in production.This section is only relevant if you want to create and feed the full dataset to Vespa. The notebook referenced in the beginning of this readme should be sufficient if you just want to spin up a scaled down version of the demo.
First, install uv:
curl -LsSf https://astral.sh/uv/install.sh | shThen, run:
uv sync --extra dev --extra feedIf you want to run the prepare_feed_deploy.py as a notebook, you can convert it using jupytext:
Convert the prepare_feed_deploy.py to notebook to:
jupytext --to notebook prepare_feed_deploy.pyAnd launch a Jupyter instance with:
uv run --with jupyter jupyter labHuge thanks to the amazing projects that made it a joy to create this demo 🙏🙌
