supervisely 6.73.367__py3-none-any.whl → 6.73.368__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.
@@ -1,11 +1,13 @@
1
1
  import json
2
2
  import time
3
3
  from os import PathLike
4
+ from pathlib import Path
4
5
  from typing import Any, Dict, Iterator, List, Literal, Tuple, Union
5
6
 
6
7
  import numpy as np
7
8
  import requests
8
9
  from requests import Timeout
10
+ from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
9
11
  from tqdm.auto import tqdm
10
12
 
11
13
  import supervisely.io.env as env
@@ -17,6 +19,7 @@ from supervisely.io.fs import (
17
19
  dir_exists,
18
20
  file_exists,
19
21
  get_file_ext,
22
+ get_file_size,
20
23
  list_files,
21
24
  list_files_recursively,
22
25
  )
@@ -374,28 +377,26 @@ class PredictionSession:
374
377
  json_body = self._get_json_body()
375
378
  return self._post(method, json=json_body).json()
376
379
 
377
- def _update_progress(self, tqdm: tqdm, response: Dict[str, Any]):
380
+ def _update_progress(
381
+ self,
382
+ tqdm: tqdm,
383
+ message: str = None,
384
+ current: int = None,
385
+ total: int = None,
386
+ is_size: bool = False,
387
+ ):
378
388
  if tqdm is None:
379
389
  return
380
- json_progress = response.get("progress", None)
381
- if json_progress is None or json_progress.get("message") is None:
382
- json_progress = response.get("preparing_progress", None)
383
- if json_progress is None:
384
- return
385
390
  refresh = False
386
- message = json_progress.get("message", json_progress.get("status", None))
387
- if message is not None and tqdm.desc not in [message, f"{message}:"]:
391
+ if message is not None and tqdm.desc != message:
388
392
  tqdm.set_description(message, refresh=False)
389
393
  refresh = True
390
- current = json_progress.get("current", None)
391
394
  if current is not None and tqdm.n != current:
392
395
  tqdm.n = current
393
396
  refresh = True
394
- total = json_progress.get("total", None)
395
397
  if total is not None and tqdm.total != total:
396
398
  tqdm.total = total
397
399
  refresh = True
398
- is_size = json_progress.get("is_size", False)
399
400
  if is_size and tqdm.unit == "it":
400
401
  tqdm.unit = "iB"
401
402
  tqdm.unit_scale = True
@@ -409,6 +410,20 @@ class PredictionSession:
409
410
  if refresh:
410
411
  tqdm.refresh()
411
412
 
413
+ def _update_progress_from_response(self, tqdm: tqdm, response: Dict[str, Any]):
414
+ if tqdm is None:
415
+ return
416
+ json_progress = response.get("progress", None)
417
+ if json_progress is None or json_progress.get("message") is None:
418
+ json_progress = response.get("preparing_progress", None)
419
+ if json_progress is None:
420
+ return
421
+ message = json_progress.get("message", json_progress.get("status", None))
422
+ current = json_progress.get("current", None)
423
+ total = json_progress.get("total", None)
424
+ is_size = json_progress.get("is_size", False)
425
+ self._update_progress(tqdm, message, current, total, is_size)
426
+
412
427
  def _wait_for_inference_start(
413
428
  self, delay=1, timeout=None, tqdm: tqdm = None
414
429
  ) -> Tuple[dict, bool]:
@@ -424,7 +439,7 @@ class PredictionSession:
424
439
  last_stage = stage
425
440
  has_started = stage not in ["preparing", "preprocess", None]
426
441
  has_started = has_started or bool(resp.get("result")) or resp["progress"]["total"] != 1
427
- self._update_progress(tqdm, resp)
442
+ self._update_progress_from_response(tqdm, resp)
428
443
  if not has_started:
429
444
  time.sleep(delay)
430
445
  timeout_exceeded = timeout and time.time() - t0 > timeout
@@ -440,7 +455,7 @@ class PredictionSession:
440
455
  t0 = time.monotonic()
441
456
  while not has_results and not timeout_exceeded:
442
457
  resp = self._pop_pending_results()
443
- self._update_progress(tqdm, resp)
458
+ self._update_progress_from_response(tqdm, resp)
444
459
  pending_results = resp["pending_results"]
445
460
  exception_json = resp["exception"]
446
461
  if exception_json:
@@ -567,14 +582,30 @@ class PredictionSession:
567
582
  state["video_id"] = videos[0]
568
583
  return self._start_inference(method, json=json_body)
569
584
  elif isinstance(videos[0], (str, PathLike)):
585
+ video_path = videos[0]
570
586
  files = []
571
587
  try:
572
588
  method = "inference_video_async"
573
- files = [("files", open(videos[0], "rb"))]
574
- uploads = files + [("state", (None, json.dumps(state), "text/plain"))]
575
- return self._start_inference(method, files=uploads)
589
+ files.append((Path(video_path).name, open(video_path, "rb"), "video/*"))
590
+ fields = {
591
+ "files": files[-1],
592
+ "state": json.dumps(state),
593
+ }
594
+ encoder = MultipartEncoder(fields)
595
+ if self.tqdm is not None:
596
+
597
+ def _callback(monitor):
598
+ self.tqdm.update(monitor.bytes_read)
599
+
600
+ video_size = get_file_size(video_path)
601
+ self._update_progress(self.tqdm, "Uploading video", 0, video_size, is_size=True)
602
+ encoder = MultipartEncoderMonitor(encoder, _callback)
603
+
604
+ return self._start_inference(
605
+ method, data=encoder, headers={"Content-Type": encoder.content_type}
606
+ )
576
607
  finally:
577
- for _, f in files:
608
+ for _, f, _ in files:
578
609
  f.close()
579
610
  else:
580
611
  raise ValueError(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.367
3
+ Version: 6.73.368
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -965,7 +965,7 @@ supervisely/nn/legacy/training/eval_planner.py,sha256=zN9b0_CX7sWGdC8e6riTvD-NOU
965
965
  supervisely/nn/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
966
966
  supervisely/nn/model/model_api.py,sha256=rIne6ymvL2aVwzSTJMGxAbevE0U-f-WKhDciqaneqRc,9666
967
967
  supervisely/nn/model/prediction.py,sha256=N3oO9s3NDiC5CFvW8utfU8rz3bfpCl37Sk4VEBH94Bc,11307
968
- supervisely/nn/model/prediction_session.py,sha256=Dk8WmO_TKuX9CbzZyzInuoGd4LniLr0oIPGTIHlcHNE,24454
968
+ supervisely/nn/model/prediction_session.py,sha256=sy0FSQaWSmT8i0RkR4J8oIn3Ek4IDVJNBR1Tg4mulkM,25523
969
969
  supervisely/nn/tracker/__init__.py,sha256=LiojByb5kGsTQ49lWuboEh7B4JUwM1vfz81J8kJlLYo,337
970
970
  supervisely/nn/tracker/tracker.py,sha256=Hs0c07l9IVF86jvjloNAGJsSZAHuNQZf0kVaUHfw3Fs,9694
971
971
  supervisely/nn/tracker/bot_sort/__init__.py,sha256=zEs5eT8NQMrM5dtSn7kbI2aWpgS2rvO7aNmrAB8v0VU,632
@@ -1097,9 +1097,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
1097
1097
  supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
1098
1098
  supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
1099
1099
  supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
1100
- supervisely-6.73.367.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1101
- supervisely-6.73.367.dist-info/METADATA,sha256=-TszuRFHXnXLeiPVh_RfMQ7badBe6_oFpbEtAZCrRAc,35154
1102
- supervisely-6.73.367.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1103
- supervisely-6.73.367.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1104
- supervisely-6.73.367.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1105
- supervisely-6.73.367.dist-info/RECORD,,
1100
+ supervisely-6.73.368.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1101
+ supervisely-6.73.368.dist-info/METADATA,sha256=xfFo1v5HarzQuLuIy2_abk6oYG3SHJcRjiw9wC9qEB4,35154
1102
+ supervisely-6.73.368.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1103
+ supervisely-6.73.368.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1104
+ supervisely-6.73.368.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1105
+ supervisely-6.73.368.dist-info/RECORD,,