diff --git a/roboflow/__init__.py b/roboflow/__init__.py index f31b4347..bfb0d133 100644 --- a/roboflow/__init__.py +++ b/roboflow/__init__.py @@ -15,7 +15,7 @@ from roboflow.models import CLIPModel, GazeModel # noqa: F401 from roboflow.util.general import write_line -__version__ = "1.1.34" +__version__ = "1.1.35" def check_key(api_key, model, notebook, num_retries=0): @@ -238,13 +238,17 @@ def workspace(self, the_workspace=None): if the_workspace is None: the_workspace = self.current_workspace - if self.api_key in DEMO_KEYS: + if self.api_key: # Check if api_key was passed during __init__ + workspace_api_key = load_roboflow_api_key(the_workspace) + api_key = workspace_api_key or self.api_key + list_projects = rfapi.get_workspace(api_key, the_workspace) + return Workspace(list_projects, api_key, the_workspace, self.model_format) + + elif self.api_key in DEMO_KEYS: return Workspace({}, self.api_key, the_workspace, self.model_format) - workspace_api_key = load_roboflow_api_key(the_workspace) - api_key = workspace_api_key or self.api_key - list_projects = rfapi.get_workspace(api_key, the_workspace) - return Workspace(list_projects, api_key, the_workspace, self.model_format) + else: + raise ValueError("A valid API key must be provided.") def project(self, project_name, the_workspace=None): """Function that takes in the name of the project and returns the project object diff --git a/roboflow/core/project.py b/roboflow/core/project.py index 1de9924c..198afb33 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -53,10 +53,8 @@ def __init__(self, api_key: str, a_project: dict, model_format: Optional[str] = >>> project = rf.workspace().project("PROJECT_ID") """ - if api_key in DEMO_KEYS: - self.__api_key = api_key - self.model_format = model_format - else: + + if api_key: self.__api_key = api_key self.annotation = a_project["annotation"] self.classes = a_project["classes"] @@ -76,6 +74,13 @@ def __init__(self, api_key: str, a_project: dict, model_format: Optional[str] = self.__workspace = temp[0] self.__project_name = temp[1] + elif DEMO_KEYS: + self.__api_key = DEMO_KEYS[0] + self.model_format = model_format + + else: + raise ValueError("A valid API key must be provided.") + def get_version_information(self): """ Retrieve all versions of a project. diff --git a/roboflow/core/version.py b/roboflow/core/version.py index 00359cf6..3e0b3218 100644 --- a/roboflow/core/version.py +++ b/roboflow/core/version.py @@ -64,19 +64,7 @@ def __init__( """ Initialize a Version object. """ - if api_key in DEMO_KEYS: - if api_key == "coco-128-sample": - self.__api_key = api_key - self.model_format = model_format - self.name = "coco-128" - self.version = "1" - else: - self.__api_key = api_key - self.model_format = model_format - self.name = "chess-pieces-new" - self.version = "23" - self.id = "joseph-nelson/chess-pieces-new" - else: + if api_key: self.__api_key = api_key self.name = name self.version = unwrap_version_id(version_id=version) @@ -145,6 +133,20 @@ def __init__( else: self.model = None + elif DEMO_KEYS: + api_key = DEMO_KEYS[0] + if api_key == "coco-128-sample": + self.__api_key = api_key + self.model_format = model_format + self.name = "coco-128" + self.version = "1" + else: + self.__api_key = api_key + self.model_format = model_format + self.name = "chess-pieces-new" + self.version = "23" + self.id = "joseph-nelson/chess-pieces-new" + def __check_if_generating(self): # check Roboflow API to see if this version is still generating diff --git a/roboflow/core/workspace.py b/roboflow/core/workspace.py index b04f92aa..c5f67a3d 100644 --- a/roboflow/core/workspace.py +++ b/roboflow/core/workspace.py @@ -25,11 +25,9 @@ class Workspace: """ def __init__(self, info, api_key, default_workspace, model_format): - if api_key in DEMO_KEYS: + if api_key: self.__api_key = api_key - self.model_format = model_format - self.project_list = [] - else: + workspace_info = info["workspace"] self.name = workspace_info["name"] self.project_list = workspace_info["projects"] @@ -38,7 +36,13 @@ def __init__(self, info, api_key, default_workspace, model_format): self.url = workspace_info["url"] self.model_format = model_format - self.__api_key = api_key + elif DEMO_KEYS: + self.__api_key = DEMO_KEYS[0] + self.model_format = model_format + self.project_list = [] + + else: + raise ValueError("A valid API key must be provided.") def list_projects(self): """ diff --git a/roboflow/roboflowpy.py b/roboflow/roboflowpy.py index c0faaa92..cf3280b9 100755 --- a/roboflow/roboflowpy.py +++ b/roboflow/roboflowpy.py @@ -113,6 +113,17 @@ def get_workspace(args): print(json.dumps(workspace_json, indent=2)) +def get_workspace_project_version(args): + # api_key = load_roboflow_api_key(args.workspaceId) + rf = roboflow.Roboflow(args.api_key) + workspace = rf.workspace() + print("workspace", workspace) + project = workspace.project(args.project) + print("project", project) + version = project.version(args.version_number) + print("version", version) + + def get_project(args): workspace_url = args.workspace or get_conditional_configuration_variable("RF_WORKSPACE", default=None) api_key = load_roboflow_api_key(workspace_url) @@ -161,6 +172,8 @@ def _argparser(): _add_projects_parser(subparsers) _add_workspaces_parser(subparsers) _add_upload_model_parser(subparsers) + _add_get_workspace_project_version_parser(subparsers) + return parser @@ -411,6 +424,35 @@ def _add_upload_model_parser(subparsers): upload_model_parser.set_defaults(func=upload_model) +def _add_get_workspace_project_version_parser(subparsers): + workspace_project_version_parser = subparsers.add_parser( + "get_workspace_info", + help="get workspace project version info", + ) + workspace_project_version_parser.add_argument( + "-a", + dest="api_key", + help="api_key", + ) + workspace_project_version_parser.add_argument( + "-w", + dest="workspace", + help="specify a workspace url or id (will use default workspace if not specified)", + ) + workspace_project_version_parser.add_argument( + "-p", + dest="project", + help="project_id to upload the model into", + ) + workspace_project_version_parser.add_argument( + "-v", + dest="version_number", + type=int, + help="version number to upload the model to", + ) + workspace_project_version_parser.set_defaults(func=get_workspace_project_version) + + def _add_login_parser(subparsers): login_parser = subparsers.add_parser("login", help="Log in to Roboflow") login_parser.set_defaults(func=login)