alessandro trinca tornidor commited on
Commit ·
f78ae56
1
Parent(s): 9b53ca4
ref: remove all the references and usages of the gradio dependency
Browse files- Dockerfile +0 -1
- README.md +8 -34
- app.py +2 -27
- docs/conf.py +2 -2
- docs/samgis_web.web.rst +0 -8
- poetry.lock +0 -0
- pyproject.toml +1 -7
Dockerfile
CHANGED
|
@@ -4,7 +4,6 @@ FROM registry.gitlab.com/aletrn/gis-prediction:1.12.1
|
|
| 4 |
ARG WORKDIR_ROOT="/var/task"
|
| 5 |
ENV VIRTUAL_ENV=${WORKDIR_ROOT}/.venv PATH="${WORKDIR_ROOT}/.venv/bin:$PATH"
|
| 6 |
ENV WRITE_TMP_ON_DISK=""
|
| 7 |
-
ENV MOUNT_GRADIO_APP=""
|
| 8 |
ENV VITE__STATIC_INDEX_URL="/static"
|
| 9 |
ENV VITE__INDEX_URL="/"
|
| 10 |
ENV HOME_USER=/home/python
|
|
|
|
| 4 |
ARG WORKDIR_ROOT="/var/task"
|
| 5 |
ENV VIRTUAL_ENV=${WORKDIR_ROOT}/.venv PATH="${WORKDIR_ROOT}/.venv/bin:$PATH"
|
| 6 |
ENV WRITE_TMP_ON_DISK=""
|
|
|
|
| 7 |
ENV VITE__STATIC_INDEX_URL="/static"
|
| 8 |
ENV VITE__INDEX_URL="/"
|
| 9 |
ENV HOME_USER=/home/python
|
README.md
CHANGED
|
@@ -22,33 +22,6 @@ If you want to use this (recommended) after the clone of this repository it's be
|
|
| 22 |
git submodule update --init --recursive
|
| 23 |
```
|
| 24 |
|
| 25 |
-
## SamGIS - Gradio SDK version
|
| 26 |
-
|
| 27 |
-
After developed your project using [the gradio quickstart](https://www.gradio.app/guides/quickstart),
|
| 28 |
-
you can declare the specific gradio version you want to use in the HuggingFace space using
|
| 29 |
-
the README.md header section. You need to compile these fields:
|
| 30 |
-
|
| 31 |
-
```
|
| 32 |
-
sdk: gradio
|
| 33 |
-
sdk_version: [current Gradio version, e.g. 4.44.0]
|
| 34 |
-
app_file: app.py
|
| 35 |
-
```
|
| 36 |
-
|
| 37 |
-
For some reason the space won't work if the app_file setting points to a file not
|
| 38 |
-
within the root folder project.
|
| 39 |
-
|
| 40 |
-
Under the hood, HuggingFace install the gradio SDK using docker. If you need to install some dependencies
|
| 41 |
-
(for this project I needed `nodejs`) you can add some system
|
| 42 |
-
[debian packages](https://huggingface.co/docs/hub/spaces-dependencies#adding-your-own-dependencies)
|
| 43 |
-
within the `pre-requirements.txt` file.
|
| 44 |
-
|
| 45 |
-
If you want to run locally the project not from a docker container you can install the optional gradio poetry group like this:
|
| 46 |
-
|
| 47 |
-
```bash
|
| 48 |
-
poetry install --with gradio --with --no-root
|
| 49 |
-
```
|
| 50 |
-
|
| 51 |
-
|
| 52 |
## SamGIS - Docker version
|
| 53 |
|
| 54 |
The SamGIS HuggingSpace url is <https://huggingface.co/spaces/aletrn/samgis>.
|
|
@@ -81,7 +54,6 @@ Run the container (keep it on background) and show logs
|
|
| 81 |
docker run -d --name samgis-huggingface -p 7860:7860 \
|
| 82 |
-e VITE__STATIC_INDEX_URL=${VITE__STATIC_INDEX_URL} \
|
| 83 |
-e VITE__INDEX_URL=${VITE__INDEX_URL} \
|
| 84 |
-
-e MOUNT_GRADIO_APP="" \
|
| 85 |
registry.gitlab.com/aletrn/samgis-huggingface; docker logs -f samgis-huggingface
|
| 86 |
```
|
| 87 |
|
|
@@ -119,7 +91,8 @@ curl -d@./events/payload_point_eolie.json -H 'content-type: application/json' ${
|
|
| 119 |
|
| 120 |
#### Local execution on MacOS
|
| 121 |
|
| 122 |
-
There is a known issue running the project on macOS. SamGIS still work also without executing it within a docker
|
|
|
|
| 123 |
|
| 124 |
```less
|
| 125 |
[...]
|
|
@@ -149,7 +122,7 @@ This problem doesn't rise if running it within the docker container.
|
|
| 149 |
Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
|
| 150 |
|
| 151 |
```bash
|
| 152 |
-
|
| 153 |
```
|
| 154 |
|
| 155 |
### How to update the static documentation with sphinx
|
|
@@ -188,8 +161,9 @@ To create a work in progress openapi json or yaml file use
|
|
| 188 |
|
| 189 |
### Update `requirements.txt` using poetry
|
| 190 |
|
| 191 |
-
``
|
| 192 |
-
|
| 193 |
-
```
|
| 194 |
|
| 195 |
-
|
|
|
|
|
|
|
|
|
| 22 |
git submodule update --init --recursive
|
| 23 |
```
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
## SamGIS - Docker version
|
| 26 |
|
| 27 |
The SamGIS HuggingSpace url is <https://huggingface.co/spaces/aletrn/samgis>.
|
|
|
|
| 54 |
docker run -d --name samgis-huggingface -p 7860:7860 \
|
| 55 |
-e VITE__STATIC_INDEX_URL=${VITE__STATIC_INDEX_URL} \
|
| 56 |
-e VITE__INDEX_URL=${VITE__INDEX_URL} \
|
|
|
|
| 57 |
registry.gitlab.com/aletrn/samgis-huggingface; docker logs -f samgis-huggingface
|
| 58 |
```
|
| 59 |
|
|
|
|
| 91 |
|
| 92 |
#### Local execution on MacOS
|
| 93 |
|
| 94 |
+
There is a known issue running the project on macOS. SamGIS still work also without executing it within a docker
|
| 95 |
+
container, but is slower during image embedding because of a memory leak caused by CoreML. Here a log about this bug:
|
| 96 |
|
| 97 |
```less
|
| 98 |
[...]
|
|
|
|
| 122 |
Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
|
| 123 |
|
| 124 |
```bash
|
| 125 |
+
pytest && coverage html
|
| 126 |
```
|
| 127 |
|
| 128 |
### How to update the static documentation with sphinx
|
|
|
|
| 161 |
|
| 162 |
### Update `requirements.txt` using poetry
|
| 163 |
|
| 164 |
+
If needed, run the create_requirements.sh script to update the `requirements.txt` file
|
| 165 |
+
(it will overwrite the existing one, asking for confirmation):
|
|
|
|
| 166 |
|
| 167 |
+
```
|
| 168 |
+
bash ./create_requirements.sh
|
| 169 |
+
```
|
app.py
CHANGED
|
@@ -34,11 +34,9 @@ folders_map = os.getenv("FOLDERS_MAP", "{}")
|
|
| 34 |
markdown_text = os.getenv("MARKDOWN_TEXT", "")
|
| 35 |
examples_text_list = os.getenv("EXAMPLES_TEXT_LIST", "").split("\n")
|
| 36 |
example_body = json.loads(os.getenv("EXAMPLE_BODY", "{}"))
|
| 37 |
-
mount_gradio_app = bool(os.getenv("MOUNT_GRADIO_APP", ""))
|
| 38 |
|
| 39 |
static_dist_folder = Path(project_root_folder) / "static" / "dist"
|
| 40 |
input_css_path = os.getenv("INPUT_CSS_PATH", "src/input.css")
|
| 41 |
-
vite_gradio_url = os.getenv("VITE_GRADIO_URL", "/gradio")
|
| 42 |
vite_index_url = os.getenv("VITE_INDEX_URL", "/")
|
| 43 |
vite_samgis_url = os.getenv("VITE_SAMGIS_URL", "/samgis")
|
| 44 |
fastapi_title = "samgis"
|
|
@@ -172,7 +170,6 @@ app_logger.info("build_frontend ok!")
|
|
| 172 |
# eventually needed for tailwindcss output.css
|
| 173 |
app.mount("/static", StaticFiles(directory=static_dist_folder, html=True), name="static")
|
| 174 |
app.mount(vite_index_url, StaticFiles(directory=static_dist_folder, html=True), name="index")
|
| 175 |
-
app.mount(vite_gradio_url, StaticFiles(directory=static_dist_folder, html=True), name="gradio")
|
| 176 |
|
| 177 |
|
| 178 |
@app.get(vite_index_url)
|
|
@@ -181,28 +178,6 @@ async def index() -> FileResponse:
|
|
| 181 |
|
| 182 |
|
| 183 |
app_logger.info(f"Mounted index on url path {vite_index_url} .")
|
| 184 |
-
app_logger.info(f"There is need to create and mount gradio app interface? {mount_gradio_app}...")
|
| 185 |
-
if mount_gradio_app:
|
| 186 |
-
try:
|
| 187 |
-
import gradio as gr
|
| 188 |
-
from samgis_web.web.gradio_helpers import get_gradio_interface_geojson
|
| 189 |
-
|
| 190 |
-
app_logger.info("creating gradio interface...")
|
| 191 |
-
gr_interface = get_gradio_interface_geojson(
|
| 192 |
-
infer_samgis_fn,
|
| 193 |
-
markdown_text,
|
| 194 |
-
examples_text_list,
|
| 195 |
-
example_body
|
| 196 |
-
)
|
| 197 |
-
app_logger.info(f"gradio interface created, mounting gradio app on url path {vite_gradio_url} within FastAPI.")
|
| 198 |
-
app_logger.debug(f"gr_interface vars:{vars(gr_interface)}.")
|
| 199 |
-
app = gr.mount_gradio_app(app, gr_interface, path=vite_gradio_url)
|
| 200 |
-
app = gr.mount_gradio_app(app, gr_interface, path="/gradio")
|
| 201 |
-
app_logger.info(f"mounted gradio app within fastapi, url path {vite_gradio_url} .")
|
| 202 |
-
except (ModuleNotFoundError, ImportError) as mnfe:
|
| 203 |
-
app_logger.error("cannot import gradio, have you installed it if you want to mount a gradio app?")
|
| 204 |
-
app_logger.error(mnfe)
|
| 205 |
-
raise mnfe
|
| 206 |
|
| 207 |
|
| 208 |
# add the CorrelationIdMiddleware AFTER the @app.middleware("http") decorated function to avoid missing request id
|
|
@@ -213,6 +188,6 @@ if __name__ == '__main__':
|
|
| 213 |
try:
|
| 214 |
uvicorn.run("app:app", host="0.0.0.0", port=7860)
|
| 215 |
except Exception as ex:
|
| 216 |
-
app_logger.error(f"fastapi
|
| 217 |
-
print(f"fastapi
|
| 218 |
raise ex
|
|
|
|
| 34 |
markdown_text = os.getenv("MARKDOWN_TEXT", "")
|
| 35 |
examples_text_list = os.getenv("EXAMPLES_TEXT_LIST", "").split("\n")
|
| 36 |
example_body = json.loads(os.getenv("EXAMPLE_BODY", "{}"))
|
|
|
|
| 37 |
|
| 38 |
static_dist_folder = Path(project_root_folder) / "static" / "dist"
|
| 39 |
input_css_path = os.getenv("INPUT_CSS_PATH", "src/input.css")
|
|
|
|
| 40 |
vite_index_url = os.getenv("VITE_INDEX_URL", "/")
|
| 41 |
vite_samgis_url = os.getenv("VITE_SAMGIS_URL", "/samgis")
|
| 42 |
fastapi_title = "samgis"
|
|
|
|
| 170 |
# eventually needed for tailwindcss output.css
|
| 171 |
app.mount("/static", StaticFiles(directory=static_dist_folder, html=True), name="static")
|
| 172 |
app.mount(vite_index_url, StaticFiles(directory=static_dist_folder, html=True), name="index")
|
|
|
|
| 173 |
|
| 174 |
|
| 175 |
@app.get(vite_index_url)
|
|
|
|
| 178 |
|
| 179 |
|
| 180 |
app_logger.info(f"Mounted index on url path {vite_index_url} .")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
|
| 183 |
# add the CorrelationIdMiddleware AFTER the @app.middleware("http") decorated function to avoid missing request id
|
|
|
|
| 188 |
try:
|
| 189 |
uvicorn.run("app:app", host="0.0.0.0", port=7860)
|
| 190 |
except Exception as ex:
|
| 191 |
+
app_logger.error(f"fastapi application {fastapi_title}, exception:{ex}.")
|
| 192 |
+
print(f"fastapi application {fastapi_title}, exception:{ex}.")
|
| 193 |
raise ex
|
docs/conf.py
CHANGED
|
@@ -21,7 +21,7 @@ with open(toml_path, "rb") as f:
|
|
| 21 |
pyproject = toml["project"]
|
| 22 |
version = pyproject["version"]
|
| 23 |
release = version
|
| 24 |
-
authors_list =
|
| 25 |
author = ""
|
| 26 |
for author_element in authors_list:
|
| 27 |
if len(author) > 1:
|
|
@@ -45,7 +45,7 @@ extensions = [
|
|
| 45 |
# 'sphinx_autodoc_defaultargs'
|
| 46 |
]
|
| 47 |
|
| 48 |
-
autodoc_mock_imports = ["fastapi", "
|
| 49 |
# Napoleon settings
|
| 50 |
napoleon_google_docstring = True
|
| 51 |
# sphinx_autodoc_typehints settings
|
|
|
|
| 21 |
pyproject = toml["project"]
|
| 22 |
version = pyproject["version"]
|
| 23 |
release = version
|
| 24 |
+
authors_list = list(pyproject["authors"])
|
| 25 |
author = ""
|
| 26 |
for author_element in authors_list:
|
| 27 |
if len(author) > 1:
|
|
|
|
| 45 |
# 'sphinx_autodoc_defaultargs'
|
| 46 |
]
|
| 47 |
|
| 48 |
+
autodoc_mock_imports = ["fastapi", "starlette"]
|
| 49 |
# Napoleon settings
|
| 50 |
napoleon_google_docstring = True
|
| 51 |
# sphinx_autodoc_typehints settings
|
docs/samgis_web.web.rst
CHANGED
|
@@ -12,14 +12,6 @@ samgis\_web.web.exception\_handlers module
|
|
| 12 |
:undoc-members:
|
| 13 |
:show-inheritance:
|
| 14 |
|
| 15 |
-
samgis\_web.web.gradio\_helpers module
|
| 16 |
-
--------------------------------------
|
| 17 |
-
|
| 18 |
-
.. automodule:: samgis_web.web.gradio_helpers
|
| 19 |
-
:members:
|
| 20 |
-
:undoc-members:
|
| 21 |
-
:show-inheritance:
|
| 22 |
-
|
| 23 |
samgis\_web.web.middlewares module
|
| 24 |
----------------------------------
|
| 25 |
|
|
|
|
| 12 |
:undoc-members:
|
| 13 |
:show-inheritance:
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
samgis\_web.web.middlewares module
|
| 16 |
----------------------------------
|
| 17 |
|
poetry.lock
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
CHANGED
|
@@ -8,7 +8,7 @@ readme = "README.md"
|
|
| 8 |
requires-python = ">=3.12, <3.14"
|
| 9 |
dependencies = [
|
| 10 |
"onnxruntime (>=1.23.2,<2.0.0)",
|
| 11 |
-
"samgis-web (==1.3.
|
| 12 |
]
|
| 13 |
|
| 14 |
[tool.poetry]
|
|
@@ -18,12 +18,6 @@ package-mode = false
|
|
| 18 |
Source = "https://github.com/trincadev/samgis-be"
|
| 19 |
Demo = "https://huggingface.co/spaces/aletrn/samgis"
|
| 20 |
|
| 21 |
-
[tool.poetry.group.gradio]
|
| 22 |
-
optional = true
|
| 23 |
-
|
| 24 |
-
[tool.poetry.group.gradio.dependencies]
|
| 25 |
-
gradio = "^5.11.0"
|
| 26 |
-
|
| 27 |
[tool.poetry.group.test]
|
| 28 |
optional = true
|
| 29 |
|
|
|
|
| 8 |
requires-python = ">=3.12, <3.14"
|
| 9 |
dependencies = [
|
| 10 |
"onnxruntime (>=1.23.2,<2.0.0)",
|
| 11 |
+
"samgis-web (==1.3.4)"
|
| 12 |
]
|
| 13 |
|
| 14 |
[tool.poetry]
|
|
|
|
| 18 |
Source = "https://github.com/trincadev/samgis-be"
|
| 19 |
Demo = "https://huggingface.co/spaces/aletrn/samgis"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
[tool.poetry.group.test]
|
| 22 |
optional = true
|
| 23 |
|