aignostics 0.2.22__tar.gz → 0.2.23__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. {aignostics-0.2.22 → aignostics-0.2.23}/PKG-INFO +1 -1
  2. {aignostics-0.2.22 → aignostics-0.2.23}/examples/notebook.py +1 -1
  3. {aignostics-0.2.22 → aignostics-0.2.23}/pyproject.toml +2 -2
  4. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/wsi/_gui.py +14 -19
  5. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/wsi/_openslide_handler.py +16 -1
  6. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/wsi/_service.py +46 -63
  7. aignostics-0.2.23/src/aignostics/wsi/assets/fallback.png +0 -0
  8. {aignostics-0.2.22 → aignostics-0.2.23}/.gitignore +0 -0
  9. {aignostics-0.2.22 → aignostics-0.2.23}/LICENSE +0 -0
  10. {aignostics-0.2.22 → aignostics-0.2.23}/README.md +0 -0
  11. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/.openapi-generator/FILES +0 -0
  12. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/.openapi-generator/VERSION +0 -0
  13. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/api/public_api.py +0 -0
  14. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/api_client.py +0 -0
  15. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/api_response.py +0 -0
  16. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/configuration.py +0 -0
  17. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/exceptions.py +0 -0
  18. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/__init__.py +0 -0
  19. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/application_read_response.py +0 -0
  20. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/application_run_status.py +0 -0
  21. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/application_version_read_response.py +0 -0
  22. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/http_validation_error.py +0 -0
  23. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/input_artifact_creation_request.py +0 -0
  24. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/input_artifact_read_response.py +0 -0
  25. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/item_creation_request.py +0 -0
  26. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/item_result_read_response.py +0 -0
  27. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/item_status.py +0 -0
  28. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/output_artifact_read_response.py +0 -0
  29. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/output_artifact_result_read_response.py +0 -0
  30. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/output_artifact_scope.py +0 -0
  31. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/payload_input_artifact.py +0 -0
  32. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/payload_item.py +0 -0
  33. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/payload_output_artifact.py +0 -0
  34. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/run_creation_request.py +0 -0
  35. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/run_creation_response.py +0 -0
  36. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/run_read_response.py +0 -0
  37. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/transfer_urls.py +0 -0
  38. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/user_payload.py +0 -0
  39. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/validation_error.py +0 -0
  40. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/models/validation_error_loc_inner.py +0 -0
  41. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/aignx/codegen/rest.py +0 -0
  42. {aignostics-0.2.22 → aignostics-0.2.23}/codegen/out/docs/PublicApi.md +0 -0
  43. {aignostics-0.2.22 → aignostics-0.2.23}/examples/__init__.py +0 -0
  44. {aignostics-0.2.22 → aignostics-0.2.23}/examples/e2e.py +0 -0
  45. {aignostics-0.2.22 → aignostics-0.2.23}/examples/notebook.ipynb +0 -0
  46. {aignostics-0.2.22 → aignostics-0.2.23}/examples/script.py +0 -0
  47. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/__init__.py +0 -0
  48. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/__init__.py +0 -0
  49. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_cli.py +0 -0
  50. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/_frame.py +0 -0
  51. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/_page_application_describe.py +0 -0
  52. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/_page_application_run_describe.py +0 -0
  53. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/_page_builder.py +0 -0
  54. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/_page_index.py +0 -0
  55. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/_utils.py +0 -0
  56. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/canceled.lottie +0 -0
  57. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/done.lottie +0 -0
  58. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/empty.lottie +0 -0
  59. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/error.lottie +0 -0
  60. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/error_alt.lottie +0 -0
  61. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/home-card-1.png +0 -0
  62. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/home-card-2.png +0 -0
  63. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/home-card-3.png +0 -0
  64. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/home-card-4.png +0 -0
  65. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/home-card-5.png +0 -0
  66. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/image-not-found.png +0 -0
  67. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/pending.lottie +0 -0
  68. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/pending_alt.lottie +0 -0
  69. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/ruo.png +0 -0
  70. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_gui/assets/ruo.svg +0 -0
  71. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_service.py +0 -0
  72. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_settings.py +0 -0
  73. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/application/_utils.py +0 -0
  74. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/bucket/__init__.py +0 -0
  75. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/bucket/_cli.py +0 -0
  76. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/bucket/_gui.py +0 -0
  77. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/bucket/_service.py +0 -0
  78. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/bucket/_settings.py +0 -0
  79. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/bucket/assets/Google-Cloud-logo.png +0 -0
  80. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/bucket/assets/Google-Cloud-logo.svg +0 -0
  81. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/cli.py +0 -0
  82. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/constants.py +0 -0
  83. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/dataset/__init__.py +0 -0
  84. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/dataset/_cli.py +0 -0
  85. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/dataset/_gui.py +0 -0
  86. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/dataset/_idc_index.py +0 -0
  87. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/dataset/_service.py +0 -0
  88. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/dataset/assets/NIH-IDC-logo.svg +0 -0
  89. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/gui/__init__.py +0 -0
  90. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/gui/_frame.py +0 -0
  91. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/gui/_theme.py +0 -0
  92. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/gui/assets/cabin-v27-latin-regular.woff2 +0 -0
  93. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/gui/assets/logo.png +0 -0
  94. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/notebook/__init__.py +0 -0
  95. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/notebook/_gui.py +0 -0
  96. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/notebook/_notebook.py +0 -0
  97. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/notebook/_service.py +0 -0
  98. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/notebook/assets/python.lottie +0 -0
  99. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/__init__.py +0 -0
  100. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/_authentication.py +0 -0
  101. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/_client.py +0 -0
  102. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/_constants.py +0 -0
  103. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/_messages.py +0 -0
  104. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/_service.py +0 -0
  105. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/_settings.py +0 -0
  106. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/_utils.py +0 -0
  107. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/resources/__init__.py +0 -0
  108. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/resources/applications.py +0 -0
  109. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/resources/runs.py +0 -0
  110. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/platform/resources/utils.py +0 -0
  111. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/qupath/__init__.py +0 -0
  112. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/qupath/_cli.py +0 -0
  113. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/qupath/_gui.py +0 -0
  114. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/qupath/_service.py +0 -0
  115. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/qupath/_settings.py +0 -0
  116. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/qupath/assets/download.lottie +0 -0
  117. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/qupath/assets/microscope.lottie +0 -0
  118. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/system/__init__.py +0 -0
  119. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/system/_cli.py +0 -0
  120. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/system/_exceptions.py +0 -0
  121. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/system/_gui.py +0 -0
  122. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/system/_service.py +0 -0
  123. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/system/_settings.py +0 -0
  124. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/.vendored/bottle.py +0 -0
  125. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/__init__.py +0 -0
  126. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_cli.py +0 -0
  127. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_console.py +0 -0
  128. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_constants.py +0 -0
  129. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_di.py +0 -0
  130. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_gui.py +0 -0
  131. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_health.py +0 -0
  132. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_log.py +0 -0
  133. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_logfire.py +0 -0
  134. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_notebook.py +0 -0
  135. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_process.py +0 -0
  136. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_sentry.py +0 -0
  137. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_service.py +0 -0
  138. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/_settings.py +0 -0
  139. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/utils/boot.py +0 -0
  140. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/wsi/__init__.py +0 -0
  141. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/wsi/_cli.py +0 -0
  142. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/wsi/_pydicom_handler.py +0 -0
  143. {aignostics-0.2.22 → aignostics-0.2.23}/src/aignostics/wsi/_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aignostics
3
- Version: 0.2.22
3
+ Version: 0.2.23
4
4
  Summary: 🔬 Python SDK providing access to the Aignostics Platform. Includes Aignostics Launchpad (Desktop Application), Aignostics CLI (Command-Line Interface), example notebooks, and Aignostics Client Library.
5
5
  Project-URL: Homepage, https://aignostics.readthedocs.io/en/latest/
6
6
  Project-URL: Documentation, https://aignostics.readthedocs.io/en/latest/
@@ -2,7 +2,7 @@
2
2
  # requires-python = ">=3.13"
3
3
  # dependencies = [
4
4
  # "marimo",
5
- # "aignostics==0.2.22",
5
+ # "aignostics==0.2.23",
6
6
  # ]
7
7
  # ///
8
8
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aignostics"
3
- version = "0.2.22"
3
+ version = "0.2.23"
4
4
  description = "🔬 Python SDK providing access to the Aignostics Platform. Includes Aignostics Launchpad (Desktop Application), Aignostics CLI (Command-Line Interface), example notebooks, and Aignostics Client Library."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -355,7 +355,7 @@ source = ["src/"]
355
355
 
356
356
 
357
357
  [tool.bumpversion]
358
- current_version = "0.2.22"
358
+ current_version = "0.2.23"
359
359
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
360
360
  serialize = ["{major}.{minor}.{patch}"]
361
361
  search = "{current_version}"
@@ -2,7 +2,8 @@
2
2
 
3
3
  from pathlib import Path
4
4
 
5
- from fastapi import HTTPException, Response
5
+ from fastapi import Response
6
+ from fastapi.responses import RedirectResponse
6
7
 
7
8
  from aignostics.utils import BasePageBuilder, get_logger
8
9
 
@@ -16,6 +17,8 @@ class PageBuilder(BasePageBuilder):
16
17
  def register_pages() -> None:
17
18
  from nicegui import app # noqa: PLC0415
18
19
 
20
+ app.add_static_files("/wsi_assets", Path(__file__).parent / "assets")
21
+
19
22
  @app.get("/thumbnail")
20
23
  def thumbnail(source: str) -> Response:
21
24
  """Serve a thumbnail for a given source reference.
@@ -24,21 +27,16 @@ class PageBuilder(BasePageBuilder):
24
27
  source (str): The source of the slide pointing to a file on the filesystem.
25
28
 
26
29
  Returns:
27
- fastapi.Response: HTTP response containing the thumbnail image.
28
-
29
- Raises:
30
- HTTPException: If the file does not exist or if thumbnail generation fails.
30
+ fastapi.Response: HTTP response containing the thumbnail or fallback image.
31
31
  """
32
32
  try:
33
33
  return Response(content=Service().get_thumbnail_bytes(Path(source)), media_type="image/png")
34
- except ValueError as e:
34
+ except ValueError:
35
35
  logger.warning("Error generating thumbnail on bad request or invalid image input")
36
- raise HTTPException(status_code=400, detail=f"Bad request or invalid image input: {e!s}") from e
37
- except RuntimeError as e:
36
+ return RedirectResponse("/wsi_assets/fallback.png")
37
+ except RuntimeError:
38
38
  logger.exception("Internal server error when generating thumbnail")
39
- raise HTTPException(
40
- status_code=500, detail=f"Internal server error when generating thumbnail: {e!s}"
41
- ) from e
39
+ return RedirectResponse("/wsi_assets/fallback.png")
42
40
 
43
41
  @app.get("/tiff")
44
42
  def tiff(url: str) -> Response:
@@ -48,16 +46,13 @@ class PageBuilder(BasePageBuilder):
48
46
  url (str): The URL of the tiff.
49
47
 
50
48
  Returns:
51
- fastapi.Response: HTTP response containing the thumbnail image.
52
-
53
- Raises:
54
- HTTPException: If the file does not exist or if thumbnail generation fails.
49
+ fastapi.Response: HTTP response containing the converted tiff or fallback image
55
50
  """
56
51
  try:
57
52
  return Response(content=Service().get_tiff_as_jpg(url), media_type="image/jpeg")
58
- except ValueError as e:
53
+ except ValueError:
59
54
  logger.warning("Error generating jpeg on bad request or invalid tiff input")
60
- raise HTTPException(status_code=400, detail=f"Bad request or invalid tiff input: {e!s}") from e
61
- except RuntimeError as e:
55
+ return RedirectResponse("/wsi_assets/fallback.png")
56
+ except RuntimeError:
62
57
  logger.exception("Internal server error when generating jpeg")
63
- raise HTTPException(status_code=500, detail=f"Internal server error when generating jpeg: {e!s}") from e
58
+ return RedirectResponse("/wsi_assets/fallback.png")
@@ -5,6 +5,7 @@ from pathlib import Path
5
5
  from typing import Any
6
6
 
7
7
  import openslide
8
+ from openslide import ImageSlide, OpenSlide, open_slide
8
9
  from PIL.Image import Image
9
10
 
10
11
  TIFF_IMAGE_DESCRIPTION = "tiff.ImageDescription"
@@ -15,10 +16,21 @@ class OpenSlideHandler:
15
16
 
16
17
  def __init__(self, path: str) -> None:
17
18
  self.path = Path(path)
18
- self.slide = openslide.OpenSlide(str(path))
19
+ self.slide: OpenSlide | ImageSlide = open_slide(str(path))
19
20
 
20
21
  @classmethod
21
22
  def from_file(cls, path: str | Path) -> "OpenSlideHandler":
23
+ """Create an OpenSlideHandler from a file path.
24
+
25
+ Args:
26
+ path (str | Path): The path to the WSI file.
27
+
28
+ Returns:
29
+ OpenSlideHandler: An instance of OpenSlideHandler initialized with the given path.
30
+
31
+ Raises:
32
+ OpenSlideError: If the file cannot be opened as a WSI.
33
+ """
22
34
  return cls(str(path))
23
35
 
24
36
  def _detect_format(self) -> str | None:
@@ -55,6 +67,9 @@ class OpenSlideHandler:
55
67
 
56
68
  Returns:
57
69
  Image: Thumbnail image of the slide.
70
+
71
+ Raises:
72
+ OpenSlideError: If the slide cannot be opened or if thumbnail generation fails.
58
73
  """
59
74
  return self.slide.get_thumbnail((256, 256))
60
75
 
@@ -12,6 +12,8 @@ logger = get_logger(__name__)
12
12
 
13
13
  TIMEOUT = 60 # 1 minutes
14
14
 
15
+ FILE_TYPES_SUPPORTED = {".dcm", ".tiff", ".tif", ".svs"}
16
+
15
17
 
16
18
  class Service(BaseService):
17
19
  """Service of the application module."""
@@ -34,58 +36,8 @@ class Service(BaseService):
34
36
  status=Health.Code.UP,
35
37
  )
36
38
 
37
- def _get_openslide_metadata(self, path: Path) -> dict[str, Any]: # noqa: PLR6301
38
- """Get metadata of a wsi file via OpenSlide.
39
-
40
- Args:
41
- path (Path): Path to the wsi file.
42
-
43
- Returns:
44
- dict[str, Any]: Metadata of the wsi file.
45
- """
46
- from ._openslide_handler import OpenSlideHandler # noqa: PLC0415
47
-
48
- handler = OpenSlideHandler.from_file(path)
49
- return handler.get_metadata()
50
-
51
- def _get_openslide_thumbnail(self, path: Path) -> "PIL.Image.Image": # type: ignore # noqa: F821, PLR6301
52
- """Get thumbnail of a wsi file via OpenSlide.
53
-
54
- Args:
55
- path (Path): Path to the wsi file.
56
-
57
- Returns:
58
- PIL.Image.Image: Thumbnail of the wsi file.
59
-
60
- Raises:
61
- OpenSlideError: If there is an error processing the wsi file with OpenSlide.
62
- """
63
- from openslide import OpenSlideError, OpenSlideUnsupportedFormatError # noqa: PLC0415
64
- from PIL import Image as PILImage # noqa: PLC0415
65
-
66
- from ._openslide_handler import OpenSlideHandler # noqa: PLC0415
67
-
68
- try:
69
- handler = OpenSlideHandler.from_file(path)
70
- return handler.get_thumbnail()
71
- except OpenSlideUnsupportedFormatError:
72
- # If OpenSlide fails, try using PIL directly
73
- img_file = PILImage.open(path)
74
- # Create a thumbnail with max size 256x256 while maintaining aspect ratio
75
- img_file.thumbnail((256, 256))
76
- # Convert to RGB mode if needed (for PNG compatibility)
77
- return img_file.convert("RGB") if img_file.mode not in {"RGB", "RGBA"} else img_file.copy()
78
- except OpenSlideError as e:
79
- if str(e) == "No pyramid levels found":
80
- # If regular OpenSlide fails, try using PIL directly
81
- img_file = PILImage.open(path)
82
- # Create a thumbnail with max size 256x256 while maintaining aspect ratio
83
- img_file.thumbnail((256, 256))
84
- # Convert to RGB mode if needed (for PNG compatibility)
85
- return img_file.convert("RGB") if img_file.mode not in {"RGB", "RGBA"} else img_file.copy()
86
- raise
87
-
88
- def get_thumbnail(self, path: Path) -> "PIL.Image.Image": # type: ignore # noqa: F821
39
+ @staticmethod
40
+ def get_thumbnail(path: Path) -> "PIL.Image.Image": # type: ignore # noqa: F821
89
41
  """Get thumbnail as PIL image.
90
42
 
91
43
  Args:
@@ -96,18 +48,27 @@ class Service(BaseService):
96
48
 
97
49
  Raises:
98
50
  ValueError: If the file type is not supported (.dcm, .tiff, or .tif).
51
+ RuntimeError: If there is an error generating the thumbnail.
99
52
  """
53
+ from ._openslide_handler import OpenSlideHandler # noqa: PLC0415
54
+
100
55
  if path.exists() is False:
101
56
  message = f"File does not exist: {path}"
102
57
  logger.warning(message)
103
58
  raise ValueError(message)
104
- if path.suffix.lower() in {".dcm", ".tiff", ".tif", ".svs"}:
105
- return self._get_openslide_thumbnail(path)
106
- message = f"Unsupported file type: {path.suffix}. Supported types are .dcm, .tiff, and .tif."
107
- logger.warning(message)
108
- raise ValueError(message)
59
+ if path.suffix.lower() not in FILE_TYPES_SUPPORTED:
60
+ message = f"Unsupported file type: {path.suffix}. Supported types are .dcm, .tiff, and .tif."
61
+ logger.warning(message)
62
+ raise ValueError(message)
63
+ try:
64
+ return OpenSlideHandler.from_file(path).get_thumbnail()
65
+ except Exception as e:
66
+ message = f"Error processing file {path}: {e!s}"
67
+ logger.exception(message)
68
+ raise RuntimeError(message) from e
109
69
 
110
- def get_thumbnail_bytes(self, path: Path) -> bytes:
70
+ @staticmethod
71
+ def get_thumbnail_bytes(path: Path) -> bytes:
111
72
  """Get thumbnail of a image as bytes.
112
73
 
113
74
  Args:
@@ -117,14 +78,16 @@ class Service(BaseService):
117
78
  bytes: Thumbnail of the image.
118
79
 
119
80
  Raises:
120
- ValueError: If the file type is not supported (.dcm, .tiff, or .tif).
81
+ ValueError: If the file type is not supported.
82
+ RuntimeError: If there is an error processing the file.
121
83
  """
122
- thumbnail_image = self.get_thumbnail(path)
84
+ thumbnail_image = Service.get_thumbnail(path)
123
85
  buffer = io.BytesIO()
124
86
  thumbnail_image.save(buffer, format="PNG")
125
87
  return buffer.getvalue()
126
88
 
127
- def get_metadata(self, path: Path) -> dict[str, Any]:
89
+ @staticmethod
90
+ def get_metadata(path: Path) -> dict[str, Any]:
128
91
  """Get metadata from a TIFF file.
129
92
 
130
93
  Args:
@@ -132,10 +95,30 @@ class Service(BaseService):
132
95
 
133
96
  Returns:
134
97
  dict[str, Any]: Metadata of the TIFF file.
98
+
99
+ Raises:
100
+ ValueError: If the file type is not supported.
101
+ RuntimeError: If there is an error processing the file.
135
102
  """
136
- return self._get_openslide_metadata(path)
103
+ from ._openslide_handler import OpenSlideHandler # noqa: PLC0415
104
+
105
+ if path.exists() is False:
106
+ message = f"File does not exist: {path}"
107
+ logger.warning(message)
108
+ raise ValueError(message)
109
+ if path.suffix.lower() not in FILE_TYPES_SUPPORTED:
110
+ message = f"Unsupported file type: {path.suffix}. Supported types are .dcm, .tiff, and .tif."
111
+ logger.warning(message)
112
+ raise ValueError(message)
113
+ try:
114
+ return OpenSlideHandler.from_file(path).get_metadata()
115
+ except Exception as e:
116
+ error_msg = f"Error processing file {path}: {e!s}"
117
+ logger.exception(error_msg)
118
+ raise RuntimeError(error_msg) from e
137
119
 
138
- def get_tiff_as_jpg(self, url: str) -> bytes: # noqa: PLR6301
120
+ @staticmethod
121
+ def get_tiff_as_jpg(url: str) -> bytes:
139
122
  """Get a TIFF image from a URL and convert it to JPG format.
140
123
 
141
124
  Args:
File without changes
File without changes
File without changes
File without changes