11import json
2- import os
3- import time
42import sys
53
64import requests
7- from roboflow .core .workspace import Workspace
5+
6+ from roboflow .config import API_URL , APP_URL , DEMO_KEYS
87from roboflow .core .project import Project
9- from roboflow .config import *
8+ from roboflow .core .workspace import Workspace
9+
1010
1111def check_key (api_key , model , notebook ):
1212 if type (api_key ) is not str :
1313 raise RuntimeError (
14- "API Key is of Incorrect Type \n Expected Type: " + str (type ("" )) + "\n Input Type: " + str (type (api_key )))
15-
16- if any (c for c in api_key if c .islower ()): #check if any of the api key characters are lowercase
14+ "API Key is of Incorrect Type \n Expected Type: "
15+ + str (type ("" ))
16+ + "\n Input Type: "
17+ + str (type (api_key ))
18+ )
19+
20+ if any (
21+ c for c in api_key if c .islower ()
22+ ): # check if any of the api key characters are lowercase
1723 if api_key in DEMO_KEYS :
18- #passthrough for public download of COCO-128 for the time being
24+ # passthrough for public download of COCO-128 for the time being
1925 return api_key
2026 else :
21- #validate key normally
27+ # validate key normally
2228 response = requests .post (API_URL + "/?api_key=" + api_key )
2329 r = response .json ()
2430
2531 if "error" in r or response .status_code != 200 :
2632 raise RuntimeError (response .text )
2733 else :
2834 return r
29- else : #then you're using a dummy key
30- sys .stdout .write ("upload and label your dataset, and get an API KEY here: " + APP_URL + "/?model=" + model + "&ref=" + notebook + "\n " )
35+ else : # then you're using a dummy key
36+ sys .stdout .write (
37+ "upload and label your dataset, and get an API KEY here: "
38+ + APP_URL
39+ + "/?model="
40+ + model
41+ + "&ref="
42+ + notebook
43+ + "\n "
44+ )
3145 return "onboarding"
3246
3347
3448def auth (api_key ):
3549 r = check_key (api_key )
36- w = r [' workspace' ]
50+ w = r [" workspace" ]
3751
3852 return Roboflow (api_key , w )
3953
4054
41- class Roboflow ():
42- def __init__ (self , api_key = "YOUR ROBOFLOW API KEY HERE" , model_format = "undefined" , notebook = "undefined" ):
55+ class Roboflow :
56+ def __init__ (
57+ self ,
58+ api_key = "YOUR ROBOFLOW API KEY HERE" ,
59+ model_format = "undefined" ,
60+ notebook = "undefined" ,
61+ ):
4362 self .api_key = api_key
4463 self .model_format = model_format
4564 self .notebook = notebook
@@ -50,14 +69,14 @@ def auth(self):
5069 r = check_key (self .api_key , self .model_format , self .notebook )
5170
5271 if r == "onboarding" :
53- self .onboarding = True
72+ self .onboarding = True
5473 return self
5574 elif r in DEMO_KEYS :
5675 self .universe = True
5776 return self
5877 else :
59- w = r [' workspace' ]
60- self .current_workspace = w
78+ w = r [" workspace" ]
79+ self .current_workspace = w
6180 return self
6281
6382 def workspace (self , the_workspace = None ):
@@ -71,7 +90,9 @@ def workspace(self, the_workspace=None):
7190 if self .api_key in DEMO_KEYS :
7291 return Workspace ({}, self .api_key , the_workspace , self .model_format )
7392
74- list_projects = requests .get (API_URL + "/" + the_workspace + '?api_key=' + self .api_key ).json ()
93+ list_projects = requests .get (
94+ API_URL + "/" + the_workspace + "?api_key=" + self .api_key
95+ ).json ()
7596
7697 return Workspace (list_projects , self .api_key , the_workspace , self .model_format )
7798
@@ -89,19 +110,25 @@ def project(self, project_name, the_workspace=None):
89110 else :
90111 the_workspace = self .current_workspace
91112
92- dataset_info = requests .get (API_URL + "/" + the_workspace + "/" + project_name + "?api_key=" + self .api_key )
113+ dataset_info = requests .get (
114+ API_URL
115+ + "/"
116+ + the_workspace
117+ + "/"
118+ + project_name
119+ + "?api_key="
120+ + self .api_key
121+ )
93122
94123 # Throw error if dataset isn't valid/user doesn't have permissions to access the dataset
95124 if dataset_info .status_code != 200 :
96125 raise RuntimeError (dataset_info .text )
97126
98- dataset_info = dataset_info .json ()[' project' ]
127+ dataset_info = dataset_info .json ()[" project" ]
99128
100129 return Project (self .api_key , dataset_info )
101130
102131 def __str__ (self ):
103- """to string function
104- """
105- json_value = {'api_key' : self .api_key ,
106- 'workspace' : self .workspace }
107- return json .dumps (json_value , indent = 2 )
132+ """to string function"""
133+ json_value = {"api_key" : self .api_key , "workspace" : self .workspace }
134+ return json .dumps (json_value , indent = 2 )
0 commit comments