Skip to content

Commit 1021cd1

Browse files
committed
add search and search_all methods
1 parent 8694dfe commit 1021cd1

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

roboflow/core/project.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,97 @@ def single_upload(
616616

617617
overall_success = success and annotation_success
618618
return overall_success
619+
620+
def search(
621+
self,
622+
like_image: str = None,
623+
prompt: str = None,
624+
offset: int = 0,
625+
limit: int = 100,
626+
tag: str = None,
627+
class_name: str = None,
628+
in_dataset: str = None,
629+
batch: bool = False,
630+
batch_id: str = None,
631+
fields: list = ["id", "created", "name", "labels"],
632+
):
633+
payload = {}
634+
635+
if like_image is not None:
636+
payload["like_image"] = like_image
637+
638+
if prompt is not None:
639+
payload["prompt"] = prompt
640+
641+
if offset is not None:
642+
payload["offset"] = offset
643+
644+
if limit is not None:
645+
payload["limit"] = limit
646+
647+
if tag is not None:
648+
payload["tag"] = tag
649+
650+
if class_name is not None:
651+
payload["class_name"] = class_name
652+
653+
if in_dataset is not None:
654+
payload["in_dataset"] = in_dataset
655+
656+
if batch is not None:
657+
payload["batch"] = batch
658+
659+
if batch_id is not None:
660+
payload["batch_id"] = batch_id
661+
662+
payload["fields"] = fields
663+
664+
data = requests.post(
665+
API_URL
666+
+ "/"
667+
+ self.__workspace
668+
+ "/"
669+
+ self.__project_name
670+
+ "/search?api_key="
671+
+ self.__api_key,
672+
json=payload,
673+
)
674+
675+
return data.json()["results"]
676+
677+
def search_all(
678+
self,
679+
like_image: str = None,
680+
prompt: str = None,
681+
offset: int = 0,
682+
limit: int = 100,
683+
tag: str = None,
684+
class_name: str = None,
685+
in_dataset: str = None,
686+
batch: bool = False,
687+
batch_id: str = None,
688+
fields: list = ["id", "created"],
689+
):
690+
while True:
691+
data = self.search(
692+
like_image=like_image,
693+
prompt=prompt,
694+
offset=offset,
695+
limit=limit,
696+
tag=tag,
697+
class_name=class_name,
698+
in_dataset=in_dataset,
699+
batch=batch,
700+
batch_id=batch_id,
701+
fields=fields,
702+
)
703+
704+
yield data
705+
706+
if len(data) < limit:
707+
break
708+
709+
offset += limit
619710

620711
def __str__(self):
621712
# String representation of project

0 commit comments

Comments
 (0)