alessandro trinca tornidor
commited on
Commit
·
39d5cde
1
Parent(s):
55adef5
feat: add gradio markdown support
Browse files- README.md +6 -3
- app.py +25 -12
- samgis_lisa_on_zero/utilities/constants.py +24 -0
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🗺️
|
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: mit
|
@@ -12,9 +12,12 @@ license: mit
|
|
12 |
|
13 |
# [LISA](https://github.com/dvlab-research/LISA) + [SamGIS](https://github.com/trincadev/samgis-be) on Zero GPU!
|
14 |
|
15 |
-
[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).
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
## Custom environment variables for HuggingFace ZeroGPU Space
|
20 |
|
|
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.38.1
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: mit
|
|
|
12 |
|
13 |
# [LISA](https://github.com/dvlab-research/LISA) + [SamGIS](https://github.com/trincadev/samgis-be) on Zero GPU!
|
14 |
|
15 |
+
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.
|
16 |
|
17 |
+
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](
|
18 |
+
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.
|
19 |
+
|
20 |
+
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.
|
21 |
|
22 |
## Custom environment variables for HuggingFace ZeroGPU Space
|
23 |
|
app.py
CHANGED
@@ -5,6 +5,7 @@ import uuid
|
|
5 |
from typing import Callable, NoReturn
|
6 |
|
7 |
import gradio as gr
|
|
|
8 |
import spaces
|
9 |
import uvicorn
|
10 |
from fastapi import FastAPI, HTTPException, Request, status
|
@@ -35,18 +36,30 @@ def gpu_initialization() -> None:
|
|
35 |
app_logger.info("GPU initialization...")
|
36 |
|
37 |
|
38 |
-
def
|
39 |
-
|
40 |
-
|
41 |
-
return
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
def handle_exception_response(exception: Exception) -> NoReturn:
|
|
|
5 |
from typing import Callable, NoReturn
|
6 |
|
7 |
import gradio as gr
|
8 |
+
from samgis_lisa_on_zero.utilities.constants import GRADIO_EXAMPLE_BODY, GRADIO_EXAMPLES_TEXT_LIST, GRADIO_MARKDOWN
|
9 |
import spaces
|
10 |
import uvicorn
|
11 |
from fastapi import FastAPI, HTTPException, Request, status
|
|
|
36 |
app_logger.info("GPU initialization...")
|
37 |
|
38 |
|
39 |
+
def get_example_complete(example_text):
|
40 |
+
example_dict = dict(**GRADIO_EXAMPLE_BODY)
|
41 |
+
example_dict["string_prompt"] = example_text
|
42 |
+
return json.dumps(example_dict)
|
43 |
+
|
44 |
+
|
45 |
+
def get_gradio_interface_geojson(fn_inference: Callable):
|
46 |
+
with gr.Blocks() as gradio_app:
|
47 |
+
gr.Markdown(GRADIO_MARKDOWN)
|
48 |
+
text_input = gr.Textbox(lines=1, placeholder=None, label="Payload input")
|
49 |
+
text_output = gr.Textbox(lines=1, placeholder=None, label="Geojson Output")
|
50 |
+
gr.Examples(
|
51 |
+
examples=[
|
52 |
+
get_example_complete(example) for example in GRADIO_EXAMPLES_TEXT_LIST
|
53 |
+
],
|
54 |
+
inputs=[text_input],
|
55 |
+
)
|
56 |
+
btn = gr.Button(value="Submit")
|
57 |
+
btn.click(
|
58 |
+
fn_inference,
|
59 |
+
inputs=[text_input],
|
60 |
+
outputs=[text_output]
|
61 |
+
)
|
62 |
+
return gradio_app
|
63 |
|
64 |
|
65 |
def handle_exception_response(exception: Exception) -> NoReturn:
|
samgis_lisa_on_zero/utilities/constants.py
CHANGED
@@ -38,3 +38,27 @@ COMPLETE_URL_TILES_NEXTZEN = f"https://{DOMAIN_URL_TILES_NEXTZEN}/{RELATIVE_URL_
|
|
38 |
CHANNEL_EXAGGERATIONS_LIST = [2.5, 1.1, 2.0]
|
39 |
SLOPE_CELLSIZE = 61
|
40 |
LISA_INFERENCE_FN = "lisa"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
CHANNEL_EXAGGERATIONS_LIST = [2.5, 1.1, 2.0]
|
39 |
SLOPE_CELLSIZE = 61
|
40 |
LISA_INFERENCE_FN = "lisa"
|
41 |
+
GRADIO_EXAMPLE_BODY = {
|
42 |
+
"bbox":{
|
43 |
+
"ne":{"lat":46.17271333276639,"lng":10.079505443573},
|
44 |
+
"sw":{"lat":46.1677724417049,"lng":10.068830251693727}
|
45 |
+
},
|
46 |
+
"string_prompt":"",
|
47 |
+
"zoom":17,
|
48 |
+
"source_type":"Esri.WorldImagery"
|
49 |
+
}
|
50 |
+
GRADIO_EXAMPLES_TEXT_LIST = [
|
51 |
+
"""You need to identify the areas with trees in this photogrammetric image. Please output segmentation mask.""",
|
52 |
+
"""You need to identify the areas with streets in this photogrammetric image. Please output segmentation mask.""",
|
53 |
+
"""You need to identify the houses in this photogrammetric image. Please output segmentation mask and explain why.""",
|
54 |
+
"""Describe what do you see in this image.""",
|
55 |
+
]
|
56 |
+
GRADIO_MARKDOWN = """# [LISA](https://github.com/dvlab-research/LISA) + [SamGIS](https://github.com/trincadev/samgis-be) on Zero GPU!
|
57 |
+
|
58 |
+
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.
|
59 |
+
|
60 |
+
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](
|
61 |
+
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.
|
62 |
+
|
63 |
+
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.
|
64 |
+
"""
|