alessandro trinca tornidor commited on
Commit
27d2629
1 Parent(s): 872cad3

[feat] permit download of tmp images if WRITE_TMP_ON_DISK env exists

Browse files
Dockerfile CHANGED
@@ -68,7 +68,8 @@ RUN git clone -n --depth=1 --filter=tree:0 https://huggingface.co/spaces/aletrn/
68
  git sparse-checkout set --no-cone resources && \
69
  git checkout
70
  WORKDIR ${LAMBDA_TASK_ROOT}
71
- RUN ls -l ${LAMBDA_TASK_ROOT}//*
 
72
 
73
  FROM pytorch/pytorch:2.2.2-cuda12.1-cudnn8-runtime as runtime
74
 
@@ -106,6 +107,8 @@ RUN corepack enable
106
  COPY ./static /appnode
107
  WORKDIR /appnode
108
  # RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then echo "pnpm store path:" && pnpm store path; fi
 
 
109
 
110
 
111
  FROM node_fastapi AS node_prod_deps
@@ -151,6 +154,7 @@ RUN ls -lh ${LAMBDA_TASK_ROOT}/machine_learning_models
151
  COPY --from=builder_global ${LAMBDA_TASK_ROOT}/lisa-on-cuda/resources ${LAMBDA_TASK_ROOT}/resources
152
  COPY --from=node_prod_deps /appnode/node_modules* ${FASTAPI_STATIC}/node_modules
153
  COPY --from=node_build /appnode/dist* ${FASTAPI_STATIC}/dist
 
154
 
155
 
156
  # Include global arg in this stage of the build
 
68
  git sparse-checkout set --no-cone resources && \
69
  git checkout
70
  WORKDIR ${LAMBDA_TASK_ROOT}
71
+ RUN ls -l ${LAMBDA_TASK_ROOT}/*
72
+
73
 
74
  FROM pytorch/pytorch:2.2.2-cuda12.1-cudnn8-runtime as runtime
75
 
 
107
  COPY ./static /appnode
108
  WORKDIR /appnode
109
  # RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then echo "pnpm store path:" && pnpm store path; fi
110
+ RUN ls -l /appnode
111
+ RUN ls -l /appnode/list_files.html
112
 
113
 
114
  FROM node_fastapi AS node_prod_deps
 
154
  COPY --from=builder_global ${LAMBDA_TASK_ROOT}/lisa-on-cuda/resources ${LAMBDA_TASK_ROOT}/resources
155
  COPY --from=node_prod_deps /appnode/node_modules* ${FASTAPI_STATIC}/node_modules
156
  COPY --from=node_build /appnode/dist* ${FASTAPI_STATIC}/dist
157
+ COPY --from=node_build /appnode/list_files.html ${FASTAPI_STATIC}/list_files.html
158
 
159
 
160
  # Include global arg in this stage of the build
static/list_files.html ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <head>
3
+ <title>Files</title>
4
+ </head>
5
+ <body>
6
+ <h1>Files:</h1>
7
+ <ul>
8
+ {% for file in files %}
9
+ <li><a href="{{file}}">{{file}}</a></li>
10
+ {% endfor %}
11
+ </ul>
12
+ </body>
13
+ </html>
static/src/components/PageLayout.vue CHANGED
@@ -16,7 +16,7 @@
16
 
17
  <main id="content" class="flex-1 z-1 lg:ml-0 mr-4 overflow-y-auto md:pl-1 lg:h-screen">
18
  <header class="hidden items-center justify-between h-10 ml-2 landscape:md:flex portrait:sd:flex portrait:md:h-12 bg-gray-200 border-b">
19
- <h2 class="hidden sd:text-sm ml-2 md:block md:text-2xl">{{ props.pageTitle }}</h2>
20
  </header>
21
 
22
  <div class="">
 
16
 
17
  <main id="content" class="flex-1 z-1 lg:ml-0 mr-4 overflow-y-auto md:pl-1 lg:h-screen">
18
  <header class="hidden items-center justify-between h-10 ml-2 landscape:md:flex portrait:sd:flex portrait:md:h-12 bg-gray-200 border-b">
19
+ <h2 class="hidden sd:text-sm ml-2 md:block md:text-2xl">{{ props.pageTitle }}</h2>
20
  </header>
21
 
22
  <div class="">
wrappers/fastapi_wrapper.py CHANGED
@@ -1,10 +1,13 @@
1
  import json
 
 
2
  import uuid
3
 
 
4
  import uvicorn
5
  from fastapi import FastAPI, HTTPException, Request, status
6
  from fastapi.exceptions import RequestValidationError
7
- from fastapi.responses import FileResponse, JSONResponse
8
  from fastapi.staticfiles import StaticFiles
9
  from pydantic import ValidationError
10
 
@@ -203,6 +206,37 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> JSONRe
203
  )
204
 
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  # important: the index() function and the app.mount MUST be at the end
207
  # samgis.html
208
  app.mount("/samgis", StaticFiles(directory=WORKDIR / "static" / "dist", html=True), name="samgis")
 
1
  import json
2
+ import os
3
+ import pathlib
4
  import uuid
5
 
6
+ from fastapi.templating import Jinja2Templates
7
  import uvicorn
8
  from fastapi import FastAPI, HTTPException, Request, status
9
  from fastapi.exceptions import RequestValidationError
10
+ from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
11
  from fastapi.staticfiles import StaticFiles
12
  from pydantic import ValidationError
13
 
 
206
  )
207
 
208
 
209
+ write_tmp_on_disk = os.getenv("WRITE_TMP_ON_DISK", "")
210
+ app_logger.info(f"write_tmp_on_disk:{write_tmp_on_disk}.")
211
+ if bool(write_tmp_on_disk):
212
+ try:
213
+ path_write_tmp_on_disk = pathlib.Path(write_tmp_on_disk)
214
+ try:
215
+ pathlib.Path.unlink(path_write_tmp_on_disk, missing_ok=True)
216
+ except PermissionError or OSError as err:
217
+ app_logger.error(f"{err} while removing old write_tmp_on_disk:{write_tmp_on_disk}.")
218
+ app_logger.error(f"is file?{path_write_tmp_on_disk.is_file()}.")
219
+ app_logger.error(f"is symlink?{path_write_tmp_on_disk.is_symlink()}.")
220
+ app_logger.error(f"is folder?{path_write_tmp_on_disk.is_dir()}.")
221
+ os.makedirs(write_tmp_on_disk, exist_ok=True)
222
+ app.mount("/vis_output", StaticFiles(directory=write_tmp_on_disk), name="vis_output")
223
+ except RuntimeError as rerr:
224
+ app_logger.error(f"{rerr} while loading the folder write_tmp_on_disk:{write_tmp_on_disk}...")
225
+ raise rerr
226
+ templates = Jinja2Templates(directory=WORKDIR / "static")
227
+
228
+
229
+ @app.get("/vis_output", response_class=HTMLResponse)
230
+ def list_files(request: Request):
231
+
232
+ files = os.listdir(write_tmp_on_disk)
233
+ files_paths = sorted([f"{request.url._url}/{f}" for f in files])
234
+ print(files_paths)
235
+ return templates.TemplateResponse(
236
+ "list_files.html", {"request": request, "files": files_paths}
237
+ )
238
+
239
+
240
  # important: the index() function and the app.mount MUST be at the end
241
  # samgis.html
242
  app.mount("/samgis", StaticFiles(directory=WORKDIR / "static" / "dist", html=True), name="samgis")