supervisely 6.73.413__py3-none-any.whl → 6.73.415__py3-none-any.whl

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.
@@ -3,7 +3,9 @@ import json
3
3
  import os
4
4
  import signal
5
5
  import sys
6
+ import time
6
7
  from contextlib import suppress
8
+ from contextvars import ContextVar
7
9
  from functools import wraps
8
10
  from pathlib import Path
9
11
  from threading import Event as ThreadingEvent
@@ -63,6 +65,9 @@ if SUPERVISELY_SERVER_PATH_PREFIX and not SUPERVISELY_SERVER_PATH_PREFIX.startsw
63
65
 
64
66
  HEALTH_ENDPOINTS = ["/health", "/is_ready"]
65
67
 
68
+ # Context variable for response time
69
+ response_time_ctx: ContextVar[float] = ContextVar("response_time", default=None)
70
+
66
71
  class ReadyzFilter(logging.Filter):
67
72
  def filter(self, record):
68
73
  if "/readyz" in record.getMessage() or "/livez" in record.getMessage():
@@ -71,11 +76,22 @@ class ReadyzFilter(logging.Filter):
71
76
  return True
72
77
 
73
78
 
79
+ class ResponseTimeFilter(logging.Filter):
80
+ def filter(self, record):
81
+ # Check if this is an HTTP access log line by logger name
82
+ if getattr(record, "name", "") == "uvicorn.access":
83
+ response_time = response_time_ctx.get(None)
84
+ if response_time is not None:
85
+ record.responseTime = int(response_time)
86
+ return True
87
+
88
+
74
89
  def _init_uvicorn_logger():
75
90
  uvicorn_logger = logging.getLogger("uvicorn.access")
76
91
  for handler in uvicorn_logger.handlers:
77
92
  handler.setFormatter(create_formatter())
78
93
  uvicorn_logger.addFilter(ReadyzFilter())
94
+ uvicorn_logger.addFilter(ResponseTimeFilter())
79
95
 
80
96
 
81
97
  _init_uvicorn_logger()
@@ -795,6 +811,8 @@ def _init(
795
811
 
796
812
  @app.middleware("http")
797
813
  async def get_state_from_request(request: Request, call_next):
814
+ # Start timer for response time measurement
815
+ start_time = time.perf_counter()
798
816
  if headless is False:
799
817
  await StateJson.from_request(request)
800
818
 
@@ -830,6 +848,9 @@ def _init(
830
848
  except Exception as exc:
831
849
  need_to_handle_error = is_production()
832
850
  response = await process_server_error(request, exc, need_to_handle_error)
851
+ # Calculate response time and set it for uvicorn logger in ms
852
+ elapsed_ms = round((time.perf_counter() - start_time) * 1000)
853
+ response_time_ctx.set(elapsed_ms)
833
854
  return response
834
855
 
835
856
  def verify_localhost(request: Request):
@@ -34,7 +34,6 @@ import supervisely.io.env as sly_env
34
34
  import supervisely.io.fs as sly_fs
35
35
  import supervisely.io.json as sly_json
36
36
  import supervisely.nn.inference.gui as GUI
37
- from supervisely.nn.experiments import ExperimentInfo
38
37
  from supervisely import DatasetInfo, batched
39
38
  from supervisely._utils import (
40
39
  add_callback,
@@ -69,13 +68,14 @@ from supervisely.decorators.inference import (
69
68
  from supervisely.geometry.any_geometry import AnyGeometry
70
69
  from supervisely.imaging.color import get_predefined_colors
71
70
  from supervisely.io.fs import list_files
71
+ from supervisely.nn.experiments import ExperimentInfo
72
72
  from supervisely.nn.inference.cache import InferenceImageCache
73
73
  from supervisely.nn.inference.inference_request import (
74
74
  InferenceRequest,
75
75
  InferenceRequestsManager,
76
76
  )
77
77
  from supervisely.nn.inference.uploader import Uploader
78
- from supervisely.nn.model.model_api import Prediction
78
+ from supervisely.nn.model.model_api import ModelAPI, Prediction
79
79
  from supervisely.nn.prediction_dto import Prediction as PredictionDTO
80
80
  from supervisely.nn.utils import (
81
81
  CheckpointInfo,
@@ -93,7 +93,6 @@ from supervisely.project.project_meta import ProjectMeta
93
93
  from supervisely.sly_logger import logger
94
94
  from supervisely.task.progress import Progress
95
95
  from supervisely.video.video import ALLOWED_VIDEO_EXTENSIONS, VideoFrameReader
96
- from supervisely.nn.model.model_api import ModelAPI
97
96
 
98
97
  try:
99
98
  from typing import Literal
@@ -383,7 +382,7 @@ class Inference:
383
382
  if m_name and m_name.lower() == model.lower():
384
383
  return m
385
384
  return None
386
-
385
+
387
386
  runtime = get_runtime(runtime)
388
387
  logger.debug(f"Runtime: {runtime}")
389
388
 
@@ -869,7 +868,7 @@ class Inference:
869
868
  """
870
869
  team_id = sly_env.team_id()
871
870
  local_model_files = {}
872
-
871
+
873
872
  # Sort files to download 'checkpoint' first
874
873
  files_order = sorted(model_files.keys(), key=lambda x: (0 if x == "checkpoint" else 1, x))
875
874
  for file in files_order:
@@ -910,12 +909,12 @@ class Inference:
910
909
  logger.debug("Model files will be downloaded from Team Files")
911
910
  local_model_files[file] = file_path
912
911
  continue
913
-
912
+
914
913
  local_model_files[file] = file_path
915
914
  if log_progress:
916
915
  self.gui.download_progress.hide()
917
916
  return local_model_files
918
-
917
+
919
918
  def _get_deploy_parameters_from_custom_checkpoint(self, checkpoint_path: str, device: str, runtime: str) -> dict:
920
919
  def _read_experiment_info(artifacts_dir: str) -> Optional[dict]:
921
920
  exp_path = os.path.join(artifacts_dir, "experiment_info.json")
@@ -1159,6 +1158,8 @@ class Inference:
1159
1158
  if model_source == ModelSource.CUSTOM:
1160
1159
  self._set_model_meta_custom_model(model_info)
1161
1160
  self._set_checkpoint_info_custom_model(deploy_params)
1161
+ elif model_source == ModelSource.PRETRAINED:
1162
+ self._set_checkpoint_info_pretrained(deploy_params)
1162
1163
 
1163
1164
  try:
1164
1165
  if is_production():
@@ -1232,6 +1233,19 @@ class Inference:
1232
1233
  model_source=ModelSource.CUSTOM,
1233
1234
  )
1234
1235
 
1236
+ def _set_checkpoint_info_pretrained(self, deploy_params: dict):
1237
+ checkpoint_name = os.path.basename(deploy_params["model_files"]["checkpoint"])
1238
+ model_name = deploy_params["model_info"]["model_name"]
1239
+ checkpoint_url = deploy_params["model_info"]["meta"]["model_files"]["checkpoint"]
1240
+ model_source = ModelSource.PRETRAINED
1241
+ self.checkpoint_info = CheckpointInfo(
1242
+ checkpoint_name=checkpoint_name,
1243
+ model_name=model_name,
1244
+ architecture=self.FRAMEWORK_NAME,
1245
+ checkpoint_url=checkpoint_url,
1246
+ model_source=model_source,
1247
+ )
1248
+
1235
1249
  def shutdown_model(self):
1236
1250
  self._model_served = False
1237
1251
  self._model_frozen = False
@@ -1447,7 +1461,7 @@ class Inference:
1447
1461
  if api is None:
1448
1462
  api = self.api
1449
1463
  return api
1450
-
1464
+
1451
1465
  def _inference_auto(
1452
1466
  self,
1453
1467
  source: List[Union[str, np.ndarray]],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.413
3
+ Version: 6.73.415
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -99,7 +99,7 @@ supervisely/app/fastapi/index.html,sha256=dz_e-0RE5ZbOU0ToUaEHe1ROI6Tc3SPL-mHt1C
99
99
  supervisely/app/fastapi/no_html_main.html,sha256=NhQP7noyORBx72lFh1CQKgBRupkWjiq6Gaw-9Hkvg7c,37
100
100
  supervisely/app/fastapi/offline.py,sha256=CwMMkJ1frD6wiZS-SEoNDtQ1UJcJe1Ob6ohE3r4CQL8,7414
101
101
  supervisely/app/fastapi/request.py,sha256=NU7rKmxJ1pfkDZ7_yHckRcRAueJRQIqCor11UO2OHr8,766
102
- supervisely/app/fastapi/subapp.py,sha256=JHJOlh6JJ43xA0WEFiH-AQlNf-XLqZmQ0qh0t24Y07w,49260
102
+ supervisely/app/fastapi/subapp.py,sha256=GxMeYMy7lCkef8R_61F2XqxKjJjtyAk7CNDSCIc07ZY,50127
103
103
  supervisely/app/fastapi/templating.py,sha256=pcghBW2OWVrNtplZuYa-mx04ektLiSvnBg-mhmyCoJc,2929
104
104
  supervisely/app/fastapi/utils.py,sha256=t_UquzlFrdkKtAJmH6eJ279pE8Aa3BaIu4XjX-SEaIE,946
105
105
  supervisely/app/fastapi/websocket.py,sha256=TlRSPOAhRItTv1HGvdukK1ZvhRjMUxRa-lJlsRR9rJw,1308
@@ -894,7 +894,7 @@ supervisely/nn/benchmark/visualization/widgets/table/__init__.py,sha256=47DEQpj8
894
894
  supervisely/nn/benchmark/visualization/widgets/table/table.py,sha256=atmDnF1Af6qLQBUjLhK18RMDKAYlxnsuVHMSEa5a-e8,4319
895
895
  supervisely/nn/inference/__init__.py,sha256=QFukX2ip-U7263aEPCF_UCFwj6EujbMnsgrXp5Bbt8I,1623
896
896
  supervisely/nn/inference/cache.py,sha256=rfmb1teJ9lNDfisUSh6bwDCVkPZocn8GMvDgLQktnbo,35023
897
- supervisely/nn/inference/inference.py,sha256=7c2-GuG3MgI5H0muTyxoR-XgUzWpbP9if37CyRewobA,198528
897
+ supervisely/nn/inference/inference.py,sha256=QTdx7RLekCs5JksRSc2skOlA9buNl05FtB6j9LcgKMQ,199183
898
898
  supervisely/nn/inference/inference_request.py,sha256=y6yw0vbaRRcEBS27nq3y0sL6Gmq2qLA_Bm0GrnJGegE,14267
899
899
  supervisely/nn/inference/session.py,sha256=dIg2F-OBl68pUzcmtmcI0YQIp1WWNnrJTVMjwFN91Q4,35824
900
900
  supervisely/nn/inference/uploader.py,sha256=21a9coOimCHhEqAbV-llZWcp12847DEMoQp3N16bpK0,5425
@@ -1115,9 +1115,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
1115
1115
  supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
1116
1116
  supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
1117
1117
  supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
1118
- supervisely-6.73.413.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1119
- supervisely-6.73.413.dist-info/METADATA,sha256=9qduIf9cJam5Kfz-s5QNls-wk1xPPVs0N28TOrDRluc,35254
1120
- supervisely-6.73.413.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1121
- supervisely-6.73.413.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1122
- supervisely-6.73.413.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1123
- supervisely-6.73.413.dist-info/RECORD,,
1118
+ supervisely-6.73.415.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1119
+ supervisely-6.73.415.dist-info/METADATA,sha256=xVB8_oba-x_gqhVFESXvrcyA2vcgOvW0qCaaPPu42wQ,35254
1120
+ supervisely-6.73.415.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1121
+ supervisely-6.73.415.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1122
+ supervisely-6.73.415.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1123
+ supervisely-6.73.415.dist-info/RECORD,,