chore: update samgis-core, samgis-web; improve imports and create_requirements.sh
Browse files- app.py +25 -17
- docs/Changelog.md +7 -0
- poetry.lock +19 -19
- pyproject.toml +8 -2
- scripts/create_requirements.sh +1 -0
app.py
CHANGED
@@ -13,9 +13,9 @@ from fastapi.staticfiles import StaticFiles
|
|
13 |
from fastapi.templating import Jinja2Templates
|
14 |
from pydantic import ValidationError
|
15 |
from samgis_core.utilities import create_folders_if_not_exists
|
|
|
16 |
from samgis_core.utilities.session_logger import setup_logging
|
17 |
from samgis_web.prediction_api.predictors import samexporter_predict
|
18 |
-
from samgis_web.utilities.frontend_builder import build_frontend
|
19 |
from samgis_web.utilities.type_hints import ApiRequestBody
|
20 |
from starlette.responses import JSONResponse
|
21 |
|
@@ -142,16 +142,17 @@ if bool(write_tmp_on_disk):
|
|
142 |
app_logger.error(f"{rerr} while loading the folder write_tmp_on_disk:{write_tmp_on_disk}...")
|
143 |
raise rerr
|
144 |
|
145 |
-
|
146 |
-
build_frontend(
|
147 |
project_root_folder=workdir,
|
148 |
input_css_path=input_css_path,
|
149 |
output_dist_folder=static_dist_folder
|
150 |
)
|
151 |
app_logger.info("build_frontend ok!")
|
152 |
|
|
|
153 |
app.mount("/static", StaticFiles(directory=static_dist_folder, html=True), name="static")
|
154 |
app.mount(vite_index_url, StaticFiles(directory=static_dist_folder, html=True), name="index")
|
|
|
155 |
|
156 |
|
157 |
@app.get(vite_index_url)
|
@@ -159,22 +160,29 @@ async def index() -> FileResponse:
|
|
159 |
return FileResponse(path=static_dist_folder / "index.html", media_type="text/html")
|
160 |
|
161 |
|
|
|
162 |
app_logger.info(f"There is need to create and mount gradio app interface? {mount_gradio_app}...")
|
163 |
if mount_gradio_app:
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
f"gradio interface created, mounting gradio app on url {vite_gradio_url} within FastAPI
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
|
180 |
# add the CorrelationIdMiddleware AFTER the @app.middleware("http") decorated function to avoid missing request id
|
|
|
13 |
from fastapi.templating import Jinja2Templates
|
14 |
from pydantic import ValidationError
|
15 |
from samgis_core.utilities import create_folders_if_not_exists
|
16 |
+
from samgis_web.utilities import frontend_builder
|
17 |
from samgis_core.utilities.session_logger import setup_logging
|
18 |
from samgis_web.prediction_api.predictors import samexporter_predict
|
|
|
19 |
from samgis_web.utilities.type_hints import ApiRequestBody
|
20 |
from starlette.responses import JSONResponse
|
21 |
|
|
|
142 |
app_logger.error(f"{rerr} while loading the folder write_tmp_on_disk:{write_tmp_on_disk}...")
|
143 |
raise rerr
|
144 |
|
145 |
+
frontend_builder.build_frontend(
|
|
|
146 |
project_root_folder=workdir,
|
147 |
input_css_path=input_css_path,
|
148 |
output_dist_folder=static_dist_folder
|
149 |
)
|
150 |
app_logger.info("build_frontend ok!")
|
151 |
|
152 |
+
# eventually needed for tailwindcss output.css
|
153 |
app.mount("/static", StaticFiles(directory=static_dist_folder, html=True), name="static")
|
154 |
app.mount(vite_index_url, StaticFiles(directory=static_dist_folder, html=True), name="index")
|
155 |
+
app.mount(vite_gradio_url, StaticFiles(directory=static_dist_folder, html=True), name="gradio")
|
156 |
|
157 |
|
158 |
@app.get(vite_index_url)
|
|
|
160 |
return FileResponse(path=static_dist_folder / "index.html", media_type="text/html")
|
161 |
|
162 |
|
163 |
+
app_logger.info(f"Mounted index on url path {vite_index_url} .")
|
164 |
app_logger.info(f"There is need to create and mount gradio app interface? {mount_gradio_app}...")
|
165 |
if mount_gradio_app:
|
166 |
+
try:
|
167 |
+
import gradio as gr
|
168 |
+
from samgis_web.web.gradio_helpers import get_gradio_interface_geojson
|
169 |
+
|
170 |
+
app_logger.info(f"creating gradio interface...")
|
171 |
+
gr_interface = get_gradio_interface_geojson(
|
172 |
+
infer_samgis_fn,
|
173 |
+
markdown_text,
|
174 |
+
examples_text_list,
|
175 |
+
example_body
|
176 |
+
)
|
177 |
+
app_logger.info(f"gradio interface created, mounting gradio app on url path {vite_gradio_url} within FastAPI.")
|
178 |
+
app_logger.debug(f"gr_interface vars:{vars(gr_interface)}.")
|
179 |
+
app = gr.mount_gradio_app(app, gr_interface, path=vite_gradio_url)
|
180 |
+
app = gr.mount_gradio_app(app, gr_interface, path="/gradio")
|
181 |
+
app_logger.info(f"mounted gradio app within fastapi, url path {vite_gradio_url} .")
|
182 |
+
except (ModuleNotFoundError, ImportError) as mnfe:
|
183 |
+
app_logger.error("cannot import gradio, have you installed it if you want to mount a gradio app?")
|
184 |
+
app_logger.error(mnfe)
|
185 |
+
raise mnfe
|
186 |
|
187 |
|
188 |
# add the CorrelationIdMiddleware AFTER the @app.middleware("http") decorated function to avoid missing request id
|
docs/Changelog.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1 |
# Changelog
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
## Version 1.6.6
|
4 |
|
5 |
- Adopt again docker SDK (we'll try Gradio SDK on duplicated HuggingFace space)
|
|
|
1 |
# Changelog
|
2 |
|
3 |
+
## Version 1.6.7
|
4 |
+
|
5 |
+
- Update samgis-core = 3.0.8, samgis-web = 1.0.9
|
6 |
+
- move frontend_builder from samgis-web to samgis-core but expose it also within samgis_web.utilities
|
7 |
+
- create_requirements.sh: handle case of of missing ./tmp/ folder
|
8 |
+
- update docs
|
9 |
+
|
10 |
## Version 1.6.6
|
11 |
|
12 |
- Adopt again docker SDK (we'll try Gradio SDK on duplicated HuggingFace space)
|
poetry.lock
CHANGED
@@ -601,12 +601,13 @@ standard = ["fastapi", "uvicorn[standard] (>=0.15.0)"]
|
|
601 |
|
602 |
[[package]]
|
603 |
name = "ffmpy"
|
604 |
-
version = "0.
|
605 |
-
description = "A simple Python wrapper for
|
606 |
optional = false
|
607 |
-
python-versions = "
|
608 |
files = [
|
609 |
-
{file = "ffmpy-0.
|
|
|
610 |
]
|
611 |
|
612 |
[[package]]
|
@@ -965,13 +966,13 @@ socks = ["socksio (==1.*)"]
|
|
965 |
|
966 |
[[package]]
|
967 |
name = "huggingface-hub"
|
968 |
-
version = "0.24.
|
969 |
description = "Client library to download and publish models, datasets and other repos on the huggingface.co hub"
|
970 |
optional = false
|
971 |
python-versions = ">=3.8.0"
|
972 |
files = [
|
973 |
-
{file = "huggingface_hub-0.24.
|
974 |
-
{file = "huggingface_hub-0.24.
|
975 |
]
|
976 |
|
977 |
[package.dependencies]
|
@@ -2541,13 +2542,13 @@ files = [
|
|
2541 |
|
2542 |
[[package]]
|
2543 |
name = "samgis-core"
|
2544 |
-
version = "3.0.
|
2545 |
description = "SamGIS CORE"
|
2546 |
optional = false
|
2547 |
python-versions = "<3.12,>=3.10"
|
2548 |
files = [
|
2549 |
-
{file = "samgis_core-3.0.
|
2550 |
-
{file = "samgis_core-3.0.
|
2551 |
]
|
2552 |
|
2553 |
[package.dependencies]
|
@@ -2562,13 +2563,13 @@ structlog = ">=24.4.0,<25.0.0"
|
|
2562 |
|
2563 |
[[package]]
|
2564 |
name = "samgis-web"
|
2565 |
-
version = "1.0.
|
2566 |
description = "SamGIS WEB"
|
2567 |
optional = false
|
2568 |
python-versions = "<3.12,>=3.10"
|
2569 |
files = [
|
2570 |
-
{file = "samgis_web-1.0.
|
2571 |
-
{file = "samgis_web-1.0.
|
2572 |
]
|
2573 |
|
2574 |
[package.dependencies]
|
@@ -2576,10 +2577,9 @@ asgi-correlation-id = ">=4.3.1,<5.0.0"
|
|
2576 |
contextily = ">=1.6.0,<2.0.0"
|
2577 |
fastapi = ">=0.111.1,<0.112.0"
|
2578 |
geopandas = ">=1.0.1,<2.0.0"
|
2579 |
-
gradio = ">=4.39.0,<5.0.0"
|
2580 |
rasterio = ">=1.3.10,<2.0.0"
|
2581 |
requests = ">=2.32.3,<3.0.0"
|
2582 |
-
samgis-core = "3.0.
|
2583 |
shapely = ">=2.0.5,<3.0.0"
|
2584 |
uvicorn = ">=0.30.1,<0.31.0"
|
2585 |
|
@@ -2600,13 +2600,13 @@ doc = ["Sphinx", "sphinx-rtd-theme"]
|
|
2600 |
|
2601 |
[[package]]
|
2602 |
name = "setuptools"
|
2603 |
-
version = "
|
2604 |
description = "Easily download, build, install, upgrade, and uninstall Python packages"
|
2605 |
optional = false
|
2606 |
python-versions = ">=3.8"
|
2607 |
files = [
|
2608 |
-
{file = "setuptools-
|
2609 |
-
{file = "setuptools-
|
2610 |
]
|
2611 |
|
2612 |
[package.extras]
|
@@ -3348,4 +3348,4 @@ files = [
|
|
3348 |
[metadata]
|
3349 |
lock-version = "2.0"
|
3350 |
python-versions = ">=3.10, <3.12"
|
3351 |
-
content-hash = "
|
|
|
601 |
|
602 |
[[package]]
|
603 |
name = "ffmpy"
|
604 |
+
version = "0.4.0"
|
605 |
+
description = "A simple Python wrapper for FFmpeg"
|
606 |
optional = false
|
607 |
+
python-versions = "<4.0.0,>=3.8.1"
|
608 |
files = [
|
609 |
+
{file = "ffmpy-0.4.0-py3-none-any.whl", hash = "sha256:39c0f20c5b465e7f8d29a5191f3a7d7675a8c546d9d985de8921151cd9b59e14"},
|
610 |
+
{file = "ffmpy-0.4.0.tar.gz", hash = "sha256:131b57794e802ad555f579007497f7a3d0cab0583d37496c685b8acae4837b1d"},
|
611 |
]
|
612 |
|
613 |
[[package]]
|
|
|
966 |
|
967 |
[[package]]
|
968 |
name = "huggingface-hub"
|
969 |
+
version = "0.24.5"
|
970 |
description = "Client library to download and publish models, datasets and other repos on the huggingface.co hub"
|
971 |
optional = false
|
972 |
python-versions = ">=3.8.0"
|
973 |
files = [
|
974 |
+
{file = "huggingface_hub-0.24.5-py3-none-any.whl", hash = "sha256:d93fb63b1f1a919a22ce91a14518974e81fc4610bf344dfe7572343ce8d3aced"},
|
975 |
+
{file = "huggingface_hub-0.24.5.tar.gz", hash = "sha256:7b45d6744dd53ce9cbf9880957de00e9d10a9ae837f1c9b7255fc8fa4e8264f3"},
|
976 |
]
|
977 |
|
978 |
[package.dependencies]
|
|
|
2542 |
|
2543 |
[[package]]
|
2544 |
name = "samgis-core"
|
2545 |
+
version = "3.0.8"
|
2546 |
description = "SamGIS CORE"
|
2547 |
optional = false
|
2548 |
python-versions = "<3.12,>=3.10"
|
2549 |
files = [
|
2550 |
+
{file = "samgis_core-3.0.8-py3-none-any.whl", hash = "sha256:eca59e6e54e16b51b69987a94ffd7bda24c1f421d0d472b20cc07d24f2fa0046"},
|
2551 |
+
{file = "samgis_core-3.0.8.tar.gz", hash = "sha256:a2934a54b8753e7aa14e0b044b031d186497605d820d0853dd7b2cc95ce4dd09"},
|
2552 |
]
|
2553 |
|
2554 |
[package.dependencies]
|
|
|
2563 |
|
2564 |
[[package]]
|
2565 |
name = "samgis-web"
|
2566 |
+
version = "1.0.9"
|
2567 |
description = "SamGIS WEB"
|
2568 |
optional = false
|
2569 |
python-versions = "<3.12,>=3.10"
|
2570 |
files = [
|
2571 |
+
{file = "samgis_web-1.0.9-py3-none-any.whl", hash = "sha256:e1b63ba9c250afe239257410f380f359cc3cc742b0ead431e9585db6eb5fa320"},
|
2572 |
+
{file = "samgis_web-1.0.9.tar.gz", hash = "sha256:d1ce20afba30b718c1bcdce03a289703b141dbceaf48bc7ddee4b83972a3af9b"},
|
2573 |
]
|
2574 |
|
2575 |
[package.dependencies]
|
|
|
2577 |
contextily = ">=1.6.0,<2.0.0"
|
2578 |
fastapi = ">=0.111.1,<0.112.0"
|
2579 |
geopandas = ">=1.0.1,<2.0.0"
|
|
|
2580 |
rasterio = ">=1.3.10,<2.0.0"
|
2581 |
requests = ">=2.32.3,<3.0.0"
|
2582 |
+
samgis-core = "3.0.8"
|
2583 |
shapely = ">=2.0.5,<3.0.0"
|
2584 |
uvicorn = ">=0.30.1,<0.31.0"
|
2585 |
|
|
|
2600 |
|
2601 |
[[package]]
|
2602 |
name = "setuptools"
|
2603 |
+
version = "72.1.0"
|
2604 |
description = "Easily download, build, install, upgrade, and uninstall Python packages"
|
2605 |
optional = false
|
2606 |
python-versions = ">=3.8"
|
2607 |
files = [
|
2608 |
+
{file = "setuptools-72.1.0-py3-none-any.whl", hash = "sha256:5a03e1860cf56bb6ef48ce186b0e557fdba433237481a9a625176c2831be15d1"},
|
2609 |
+
{file = "setuptools-72.1.0.tar.gz", hash = "sha256:8d243eff56d095e5817f796ede6ae32941278f542e0f941867cc05ae52b162ec"},
|
2610 |
]
|
2611 |
|
2612 |
[package.extras]
|
|
|
3348 |
[metadata]
|
3349 |
lock-version = "2.0"
|
3350 |
python-versions = ">=3.10, <3.12"
|
3351 |
+
content-hash = "5fd17cc79aeaff12229f2d06f428d184256fa24f67fb70a933c674a470d43d7e"
|
pyproject.toml
CHANGED
@@ -28,8 +28,14 @@ python-dotenv = "^1.0.1"
|
|
28 |
onnxruntime = "^1.18.1"
|
29 |
rasterio = "^1.3.10"
|
30 |
requests = "^2.32.3"
|
31 |
-
samgis-core = "3.0.
|
32 |
-
samgis-web = "1.0.
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
[tool.poetry.group.test]
|
35 |
optional = true
|
|
|
28 |
onnxruntime = "^1.18.1"
|
29 |
rasterio = "^1.3.10"
|
30 |
requests = "^2.32.3"
|
31 |
+
samgis-core = "3.0.8"
|
32 |
+
samgis-web = "1.0.9"
|
33 |
+
|
34 |
+
[tool.poetry.group.gradio]
|
35 |
+
optional = true
|
36 |
+
|
37 |
+
[tool.poetry.group.gradio.dependencies]
|
38 |
+
gradio = "^4.39.0"
|
39 |
|
40 |
[tool.poetry.group.test]
|
41 |
optional = true
|
scripts/create_requirements.sh
CHANGED
@@ -4,6 +4,7 @@ SCRIPT=$(realpath "$0")
|
|
4 |
SCRIPT_FOLDER=$(dirname "$SCRIPT")
|
5 |
ROOT_FOLDER=${SCRIPT_FOLDER}/../
|
6 |
|
|
|
7 |
rm ./tmp/requirements_tmp.txt || echo "./tmp/requirements_tmp.txt not found!"
|
8 |
|
9 |
echo "start requirements.txt preparation: pip freeze..."
|
|
|
4 |
SCRIPT_FOLDER=$(dirname "$SCRIPT")
|
5 |
ROOT_FOLDER=${SCRIPT_FOLDER}/../
|
6 |
|
7 |
+
mkdir -p tmp
|
8 |
rm ./tmp/requirements_tmp.txt || echo "./tmp/requirements_tmp.txt not found!"
|
9 |
|
10 |
echo "start requirements.txt preparation: pip freeze..."
|