samgis-lisa-on-cuda / README.md
alessandro trinca tornidor
ci: revert to docker sdk, bump pytorch docker image to pytorch:2.4.1-cuda12.4-cudnn9-runtime
d326f12
metadata
title: SamGIS - LISA on CUDA
emoji: 🗺️
colorFrom: red
colorTo: blue
sdk: docker
app_file: app.py
pinned: true
license: mit

LISA + SamGIS on a dedicated CUDA GPU

This project aims to permit use of LISA (Reasoning Segmentation via Large Language Model) applied to geospatial data thanks to SamGIS. In this space I adapted LISA to HuggingFace lisa-on-cuda ZeroGPU space.

This home page project is a plane Gradio interface that take a json in input to translate it to a geojson. More information about these API implementation here. On this blog page you can find more details, including some request and response examples with the geojson map representations.

You can also find the alternative map interface here useful to create on the fly the payload requests and to represent the geojson response.

Custom environment variables for HuggingFace CUDA Space

Fundamental environment variables you need are:

XDG_CACHE_HOME="/data/.cache"
PROJECT_ROOT_FOLDER="/home/user/app"
WORKDIR="/home/user/app"

Derived ones:

MPLCONFIGDIR="/data/.cache/matplotlib"
TRANSFORMERS_CACHE="/data/.cache/transformers"
PYTORCH_KERNEL_CACHE_PATH="/data/.cache/torch/kernels"
FASTAPI_STATIC="/home/user/app/static"
VIS_OUTPUT="/home/user/app/vis_output"
MODEL_FOLDER="/home/user/app/machine_learning_models"
FOLDERS_MAP='{"WORKDIR":"/home/user/app","XDG_CACHE_HOME":"/data/.cache","PROJECT_ROOT_FOLDER":"/home/user/app","MPLCONFIGDIR":"/data/.cache/matplotlib","TRANSFORMERS_CACHE":"/data/.cache/transformers","PYTORCH_KERNEL_CACHE_PATH":"/data/.cache/torch/kernels","FASTAPI_STATIC":"/home/user/app/static","VIS_OUTPUT":"/home/user/app/vis_output"}'

The function build_frontend() from lisa_on_cuda package create all the folders required for this project using the environment variable FOLDERS_MAP. That's useful for cache folders (XDG_CACHE_HOME, MPLCONFIGDIR, TRANSFORMERS_CACHE, PYTORCH_KERNEL_CACHE_PATH) because missing these can slow down the inference process. Also you could keep these folders in a permanent storage disk mounted on a custom path.

To change the base relative url for custom frontend add the VITE_PREFIX environment variable, e.g.:

VITE_INDEX_URL="/custom-url"

About HuggingFace space dependencies

For this demo simply installing samgis-lisa already brings all the needed dependencies. Now lisa.lisa_predict() has the optional argument inference_decorator useful in case of use on ZeroGPU hardware or similar.