File size: 3,434 Bytes
b00385f
5350122
0914710
 
b00385f
d326f12
2dbe20c
 
0914710
b00385f
 
2dbe20c
9bee93c
2dbe20c
9bee93c
2dbe20c
 
0c9e62a
2dbe20c
0914710
2dbe20c
0914710
2dbe20c
0914710
 
2dbe20c
 
 
0914710
 
2dbe20c
0914710
 
2dbe20c
 
 
 
 
 
 
0914710
 
2dbe20c
0914710
2dbe20c
0914710
 
2dbe20c
0914710
 
0630615
 
 
 
 
74dd214
0630615
 
 
 
74dd214
0630615
2dbe20c
0c9e62a
2dbe20c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: SamGIS - LISA on CUDA
emoji: 🗺️
colorFrom: red
colorTo: blue
sdk: docker
app_file: app.py
pinned: true
license: mit
---

# [LISA](https://github.com/dvlab-research/LISA) + [SamGIS](https://github.com/trincadev/samgis-be) on a dedicated CUDA GPU

This project aims to permit use of [LISA](https://github.com/dvlab-research/LISA) (Reasoning Segmentation via Large Language Model) applied to geospatial data thanks to [SamGIS](https://github.com/trincadev/samgis-be). In this space I adapted LISA to HuggingFace [lisa-on-cuda](https://huggingface.co/spaces/aletrn/lisa-on-cuda) ZeroGPU space.

This [home page project](https://huggingface.co/spaces/aletrn/samgis-lisa-on-zero) is a plane Gradio interface that take a json in input to translate it to a geojson. More information about these API implementation [here](
https://aletrn-samgis-lisa-on-zero.hf.space/docs). On this [blog page](https://trinca.tornidor.com/projects/lisa-adapted-for-samgis) 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](https://aletrn-samgis-lisa-on-zero.hf.space/lisa/) 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:

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

Derived ones:

```bash
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.:

```bash
VITE_INDEX_URL="/custom-url"
```

## Local environment

To execute the you can simply run from the root project folder:

- `python app.py`
- `python -m uvicorn app:app --host 0.0.0.0 --port 7860`

It's also possible to make and run a docker build:

- `docker build . -t registry.gitlab.com/aletrn/samgis-lisa-on-cuda --progress=plain`
- `docker run -d --name samgis-lisa -p 7860:7860 --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 registry.gitlab.com/aletrn/samgis-lisa; docker logs -f samgis-lisa-on-cuda`

## 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.