alessandro trinca tornidor
commited on
Commit
·
9813432
1
Parent(s):
7d2bd36
feat: handle custom urls with env variables: CUSTOM_INDEX_URL, CUSTOM_SAMGIS_URL, CUSTOM_LISA_URL, CUSTOM_GRADIO_URL
Browse files
app.py
CHANGED
|
@@ -22,8 +22,10 @@ from samgis_lisa_on_zero.utilities.type_hints import ApiRequestBody, StringPromp
|
|
| 22 |
loglevel = os.getenv('LOGLEVEL', 'INFO').upper()
|
| 23 |
app_logger = setup_logging(debug=loglevel)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
FASTAPI_TITLE = "samgis-lisa-on-zero"
|
| 28 |
app = FastAPI(title=FASTAPI_TITLE, version="1.0")
|
| 29 |
|
|
@@ -65,16 +67,16 @@ async def health() -> JSONResponse:
|
|
| 65 |
import importlib.metadata
|
| 66 |
from importlib.metadata import PackageNotFoundError
|
| 67 |
|
| 68 |
-
core_version = lisa_on_cuda_version =
|
| 69 |
try:
|
| 70 |
core_version = importlib.metadata.version('samgis_core')
|
| 71 |
lisa_on_cuda_version = importlib.metadata.version('lisa-on-cuda')
|
| 72 |
-
|
| 73 |
except PackageNotFoundError as pe:
|
| 74 |
app_logger.error(f"pe:{pe}.")
|
| 75 |
|
| 76 |
msg = "still alive, "
|
| 77 |
-
msg += f"""version:{
|
| 78 |
msg += f"""lisa-on-cuda version:{lisa_on_cuda_version},"""
|
| 79 |
|
| 80 |
app_logger.info(msg)
|
|
@@ -261,28 +263,28 @@ templates = Jinja2Templates(directory="templates")
|
|
| 261 |
|
| 262 |
# important: the index() function and the app.mount MUST be at the end
|
| 263 |
# samgis.html
|
| 264 |
-
app.mount(
|
| 265 |
|
| 266 |
|
| 267 |
-
@app.get(
|
| 268 |
async def samgis() -> FileResponse:
|
| 269 |
return FileResponse(path=static_dist_folder / "samgis.html", media_type="text/html")
|
| 270 |
|
| 271 |
|
| 272 |
# lisa.html
|
| 273 |
-
app.mount(
|
| 274 |
|
| 275 |
|
| 276 |
-
@app.get(
|
| 277 |
async def lisa() -> FileResponse:
|
| 278 |
return FileResponse(path=static_dist_folder / "lisa.html", media_type="text/html")
|
| 279 |
|
| 280 |
|
| 281 |
# # index.html (lisa.html copy)
|
| 282 |
-
app.mount(
|
| 283 |
|
| 284 |
|
| 285 |
-
@app.get(
|
| 286 |
async def index() -> FileResponse:
|
| 287 |
return FileResponse(path=static_dist_folder / "index.html", media_type="text/html")
|
| 288 |
|
|
@@ -292,8 +294,8 @@ inference_fn = app_helpers.get_inference_model_by_args(args, inference_decorator
|
|
| 292 |
|
| 293 |
app_helpers.app_logger.info(f"prepared inference_fn function:{inference_fn.__name__}, creating gradio interface...")
|
| 294 |
io = app_helpers.get_gradio_interface(inference_fn)
|
| 295 |
-
app_helpers.app_logger.info("created gradio interface, mounting gradio app within FastAPI...")
|
| 296 |
-
app = gr.mount_gradio_app(app, io, path=
|
| 297 |
app_helpers.app_logger.info("mounted gradio app within fastapi")
|
| 298 |
|
| 299 |
|
|
|
|
| 22 |
loglevel = os.getenv('LOGLEVEL', 'INFO').upper()
|
| 23 |
app_logger = setup_logging(debug=loglevel)
|
| 24 |
|
| 25 |
+
CUSTOM_INDEX_URL = os.getenv("CUSTOM_INDEX_URL", "/")
|
| 26 |
+
CUSTOM_SAMGIS_URL = os.getenv("CUSTOM_SAMGIS_URL", "/samgis")
|
| 27 |
+
CUSTOM_LISA_URL = os.getenv("CUSTOM_LISA_URL", "/lisa")
|
| 28 |
+
CUSTOM_GRADIO_URL = os.getenv("CUSTOM_GRADIO_URL", "/gradio")
|
| 29 |
FASTAPI_TITLE = "samgis-lisa-on-zero"
|
| 30 |
app = FastAPI(title=FASTAPI_TITLE, version="1.0")
|
| 31 |
|
|
|
|
| 67 |
import importlib.metadata
|
| 68 |
from importlib.metadata import PackageNotFoundError
|
| 69 |
|
| 70 |
+
core_version = lisa_on_cuda_version = samgis_lisa_on_cuda_version = ""
|
| 71 |
try:
|
| 72 |
core_version = importlib.metadata.version('samgis_core')
|
| 73 |
lisa_on_cuda_version = importlib.metadata.version('lisa-on-cuda')
|
| 74 |
+
samgis_lisa_on_cuda_version = importlib.metadata.version('samgis-lisa-on-zero')
|
| 75 |
except PackageNotFoundError as pe:
|
| 76 |
app_logger.error(f"pe:{pe}.")
|
| 77 |
|
| 78 |
msg = "still alive, "
|
| 79 |
+
msg += f"""version:{samgis_lisa_on_cuda_version}, core version:{core_version},"""
|
| 80 |
msg += f"""lisa-on-cuda version:{lisa_on_cuda_version},"""
|
| 81 |
|
| 82 |
app_logger.info(msg)
|
|
|
|
| 263 |
|
| 264 |
# important: the index() function and the app.mount MUST be at the end
|
| 265 |
# samgis.html
|
| 266 |
+
app.mount(CUSTOM_SAMGIS_URL, StaticFiles(directory=static_dist_folder, html=True), name="samgis")
|
| 267 |
|
| 268 |
|
| 269 |
+
@app.get(CUSTOM_SAMGIS_URL)
|
| 270 |
async def samgis() -> FileResponse:
|
| 271 |
return FileResponse(path=static_dist_folder / "samgis.html", media_type="text/html")
|
| 272 |
|
| 273 |
|
| 274 |
# lisa.html
|
| 275 |
+
app.mount(CUSTOM_LISA_URL, StaticFiles(directory=static_dist_folder, html=True), name="lisa")
|
| 276 |
|
| 277 |
|
| 278 |
+
@app.get(CUSTOM_LISA_URL)
|
| 279 |
async def lisa() -> FileResponse:
|
| 280 |
return FileResponse(path=static_dist_folder / "lisa.html", media_type="text/html")
|
| 281 |
|
| 282 |
|
| 283 |
# # index.html (lisa.html copy)
|
| 284 |
+
app.mount(CUSTOM_INDEX_URL, StaticFiles(directory=static_dist_folder, html=True), name="index")
|
| 285 |
|
| 286 |
|
| 287 |
+
@app.get(CUSTOM_INDEX_URL)
|
| 288 |
async def index() -> FileResponse:
|
| 289 |
return FileResponse(path=static_dist_folder / "index.html", media_type="text/html")
|
| 290 |
|
|
|
|
| 294 |
|
| 295 |
app_helpers.app_logger.info(f"prepared inference_fn function:{inference_fn.__name__}, creating gradio interface...")
|
| 296 |
io = app_helpers.get_gradio_interface(inference_fn)
|
| 297 |
+
app_helpers.app_logger.info(f"created gradio interface, mounting gradio app on url {CUSTOM_GRADIO_URL} within FastAPI...")
|
| 298 |
+
app = gr.mount_gradio_app(app, io, path=CUSTOM_GRADIO_URL)
|
| 299 |
app_helpers.app_logger.info("mounted gradio app within fastapi")
|
| 300 |
|
| 301 |
|