Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions examples/pop_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def list_of_boxes(arg: str) -> list[dict[str, any]]:
parser.add_argument('-pr', '--prompt', required=False, type=str, help="Prompt to pass as parameter", action="append")
parser.add_argument('-v', '--visualize', required=False, help="show rendered output", default=False, action="store_true")
parser.add_argument('-o', '--output', required=False, help="print results to stdout", default=False, action="store_true")
parser.add_argument('-ds', '--dataset-uuid', required=False, type=str, help="Ingest all assets into a dataset uuid", default=None)


args = parser.parse_args()
Expand All @@ -266,7 +267,7 @@ def list_of_boxes(arg: str) -> list[dict[str, any]]:
parser.print_help()
sys.exit(1)

with EyePopSdk.workerEndpoint() as endpoint:
with EyePopSdk.workerEndpoint(dataset_uuid=args.dataset_uuid) as endpoint:
if args.pop:
endpoint.set_pop(pop_examples[args.pop])
elif args.model_uuid:
Expand Down Expand Up @@ -356,13 +357,27 @@ def list_of_boxes(arg: str) -> list[dict[str, any]]:
})
]
if args.local_path:
job = endpoint.upload(args.local_path, params=params)
while result := job.predict():
visualize_result = result
if args.output:
logging.getLogger('eyepop.example').info(json.dumps(result, indent=2))
if not os.path.exists(args.local_path):
print(f"local path {args.local_path} does not exist")
sys.exit(1)
if os.path.isfile(args.local_path):
local_files = [args.local_path]
else:
local_files = []

for f in os.listdir(args.local_path):
local_file = os.path.join(args.local_path, f)
if os.path.isfile(local_file):
local_files.append(local_file)
for local_file in local_files:
job = endpoint.upload(local_file, params=params)
while result := job.predict():
visualize_result = result
visualize_path = local_file
if args.output:
logging.getLogger('eyepop.example').info(json.dumps(result, indent=2))
if args.visualize:
image = Image.open(args.local_path)
image = Image.open(visualize_path)
buffer = BytesIO()
image.save(buffer, format="PNG")
example_image_src = f"data:image/png;base64, {base64.b64encode(buffer.getvalue()).decode()}"
Expand Down
35 changes: 26 additions & 9 deletions eyepop/eyepopsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ class EyePopSdk:
"""

@staticmethod
def workerEndpoint(pop_id: str | None = None, secret_key: str | None = None, access_token: str | None = None,
auto_start: bool = True, stop_jobs: bool = True,
eyepop_url: str | None = None, job_queue_length: int = 1024,
is_async: bool = False, is_sandbox: bool = False, is_local_mode: bool | None = None,
request_tracer_max_buffer: int = 1204) -> WorkerEndpoint | SyncWorkerEndpoint:
def workerEndpoint(
pop_id: str | None = None,
secret_key: str | None = None,
access_token: str | None = None,
auto_start: bool = True,
stop_jobs: bool = True,
eyepop_url: str | None = None,
job_queue_length: int = 1024,
is_async: bool = False,
is_sandbox: bool = False,
is_local_mode: bool | None = None,
request_tracer_max_buffer: int = 1204,
dataset_uuid: str | None = None
) -> WorkerEndpoint | SyncWorkerEndpoint:
if is_local_mode is None:
is_local_mode = os.getenv('EYEPOP_LOCAL_MODE')
if is_local_mode is not None:
Expand Down Expand Up @@ -50,10 +59,18 @@ def workerEndpoint(pop_id: str | None = None, secret_key: str | None = None, acc
if pop_id is None:
pop_id= 'transient'

endpoint = WorkerEndpoint(secret_key=secret_key, access_token=access_token,
pop_id=pop_id, auto_start=auto_start, stop_jobs=stop_jobs,
eyepop_url=eyepop_url, job_queue_length=job_queue_length, is_sandbox=is_sandbox,
request_tracer_max_buffer=request_tracer_max_buffer)
endpoint = WorkerEndpoint(
secret_key=secret_key,
access_token=access_token,
pop_id=pop_id,
auto_start=auto_start,
stop_jobs=stop_jobs,
eyepop_url=eyepop_url,
job_queue_length=job_queue_length,
is_sandbox=is_sandbox,
request_tracer_max_buffer=request_tracer_max_buffer,
dataset_uuid=dataset_uuid,
)

if not is_async:
endpoint = SyncWorkerEndpoint(endpoint)
Expand Down
55 changes: 45 additions & 10 deletions eyepop/worker/worker_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,31 @@ class WorkerEndpoint(Endpoint, WorkerClientSession):
Endpoint to an EyePop.ai worker.
"""

def __init__(self, secret_key: str | None, access_token: str | None,
eyepop_url: str, pop_id: str, auto_start: bool, stop_jobs: bool,
job_queue_length: int, is_sandbox: bool, request_tracer_max_buffer: int):
def __init__(
self,
secret_key: str | None,
access_token: str | None,
eyepop_url: str,
pop_id: str,
auto_start: bool,
stop_jobs: bool,
job_queue_length: int,
is_sandbox: bool,
request_tracer_max_buffer: int,
dataset_uuid: str | None = None,
):
super().__init__(
secret_key=secret_key, access_token=access_token, eyepop_url=eyepop_url,
job_queue_length=job_queue_length, request_tracer_max_buffer=request_tracer_max_buffer
secret_key=secret_key,
access_token=access_token,
eyepop_url=eyepop_url,
job_queue_length=job_queue_length,
request_tracer_max_buffer=request_tracer_max_buffer
)
self.pop_id = pop_id
self.auto_start = auto_start
self.stop_jobs = stop_jobs
self.is_sandbox = is_sandbox
self.dataset_uuid = dataset_uuid

self.sandbox_id = None

Expand Down Expand Up @@ -177,14 +191,35 @@ async def _reconnect(self):
else:
start_pipeline_url = f'{base_url}/pipelines?sandboxId={self.sandbox_id}'
if self.pop is not None:
body = {"pop": self.pop, "source": {"sourceType": "NONE"},
"idleTimeoutSeconds": 60, "logging": ["out_meta"], "videoOutput": "no_output"}
body = {
"pop": self.pop,
"source": {
"sourceType": "NONE"
},
"idleTimeoutSeconds": 60,
"logging": ["out_meta"],
"videoOutput": "no_output",
"datasetUuid": self.dataset_uuid,
}
else:
if self.pop_comp is None:
self.pop_comp = 'identity'
body = {'inferPipelineDef': {'pipeline': self.pop_comp, 'modelRefs': self.model_refs},
'postTransformDef': {'transform': self.post_transform}, "source": {"sourceType": "NONE"},
"idleTimeoutSeconds": 60, "logging": ["out_meta"], "videoOutput": "no_output"}
body = {
'inferPipelineDef': {
'pipeline': self.pop_comp,
'modelRefs': self.model_refs
},
'postTransformDef': {
'transform': self.post_transform
},
"source": {
"sourceType": "NONE"
},
"idleTimeoutSeconds": 60,
"logging": ["out_meta"],
"videoOutput": "no_output",
"datasetUuid": self.dataset_uuid,
}

headers = {}
authorization_header = await self._authorization_header()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "eyepop"
version = "1.15.5"
version = "1.15.6"
description="EyePop.ai Python SDK"
readme = "README.md"
license.file = "./LICENSE"
Expand Down