Skip to content

Commit 7fe53d3

Browse files
committed
grant fetch annotation_import updates
1 parent 0fdd61d commit 7fe53d3

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ If the installation completes with a warning re: pip not being in your path, you
3535
export PATH=/Users/<your-macOS-username>/Library/Python/3.8/bin:$PATH
3636
```
3737

38-
Install using Python's Pip manager.
38+
Install SDK locally, using Python's Pip manager
3939
```
40-
pip install labelbox
40+
pip3 install -e .
41+
```
42+
43+
Install dependencies
44+
```
45+
pip3 install -r requirements.txt
4146
```
4247

4348
## Documentation
@@ -55,7 +60,7 @@ user@machine:~$ export LABELBOX_API_KEY="<your api key here>"
5560
user@machine:~$ python3
5661
5762
from labelbox import Client
58-
client = Client()
63+
client = Client(api_key="your_key_here", endpoint="http://localhost:8080/_gql")
5964
```
6065

6166
## Contribution

labelbox/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ def check_errors(keywords, *path):
192192
if obj in keywords:
193193
return error
194194
return None
195+
196+
def get_error_status_code(error):
197+
return error["extensions"]["exception"]["status"]
195198

196199
if check_errors(["AUTHENTICATION_ERROR"], "extensions",
197200
"code") is not None:
@@ -240,7 +243,7 @@ def check_errors(keywords, *path):
240243
if internal_server_error is not None:
241244
message = internal_server_error.get("message")
242245

243-
if message.startswith(("Syntax Error", "Invite(s) cannot be sent")):
246+
if get_error_status_code(internal_server_error) == 400:
244247
raise labelbox.exceptions.InvalidQueryError(message)
245248
else:
246249
raise labelbox.exceptions.InternalServerError(message)

labelbox/schema/annotation_import.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,6 @@ def _fetch_remote_ndjson(self, url: str) -> List[Dict[str, Any]]:
118118
response.raise_for_status()
119119
return ndjson.loads(response.text)
120120

121-
@classmethod
122-
def _from_name(cls,
123-
client: "labelbox.Client",
124-
parent_id: str,
125-
name: str,
126-
raw=False
127-
) -> Union["MEAPredictionImport", "MALPredictionImport"]:
128-
query_str = """query getImportPyApi($parent_id : ID!, $name: String!) {
129-
annotationImport(
130-
where: {%s: $parent_id, name: $name}){
131-
__typename
132-
... on ModelAssistedLabelingPredictionImport {%s}
133-
... on ModelErrorAnalysisPredictionImport {%s}
134-
}}""" % \
135-
(
136-
cls._parent_id_field,
137-
query.results_query_part(MALPredictionImport),
138-
query.results_query_part(MEAPredictionImport)
139-
)
140-
141-
response = client.execute(query_str, {
142-
'name': name,
143-
'parent_id': parent_id
144-
})
145-
if raw:
146-
return response['annotationImport']
147-
148-
return cls(client, response['annotationImport'])
149-
150121
@staticmethod
151122
def _make_file_name(parent_id: str, name: str) -> str:
152123
return f"{parent_id}__{name}.ndjson"
@@ -269,12 +240,26 @@ def create_from_url(cls, client: "labelbox.Client", model_run_id: str,
269240
parent_id=model_run_id,
270241
name=name,
271242
url=url)
272-
243+
273244
@classmethod
274245
def from_name(
275246
cls, client: "labelbox.Client", model_run_id: str,
276-
name: str) -> Union["MEAPredictionImport", "MALPredictionImport"]:
277-
return cls._from_name(client, model_run_id, name)
247+
name: str) -> "MEAPredictionImport":
248+
249+
query_str = """query getModelErrorAnalysisPredictionImportPyApi($modelRunId : ID!, $name: String!) {
250+
modelErrorAnalysisPredictionImport(
251+
where: {modelRunId: $modelRunId, name: $name}){
252+
%s
253+
}}""" % query.results_query_part(cls)
254+
params = {
255+
"modelRunId": model_run_id,
256+
"name": name,
257+
}
258+
response = client.execute(query_str, params)
259+
if response is None:
260+
raise labelbox.exceptions.ResourceNotFoundError(MEAPredictionImport, params)
261+
262+
return response
278263

279264

280265
class MALPredictionImport(AnnotationImport):
@@ -310,5 +295,19 @@ def create_from_url(cls, client: "labelbox.Client", project_id: str,
310295
@classmethod
311296
def from_name(
312297
cls, client: "labelbox.Client", project_id: str,
313-
name: str) -> Union["MEAPredictionImport", "MALPredictionImport"]:
314-
return cls._from_name(client, project_id, name)
298+
name: str) -> "MALPredictionImport":
299+
300+
query_str = """query getModelAssistedLabelingPredictionImportPyApi($projectId : ID!, $name: String!) {
301+
modelAssistedLabelingPredictionImport(
302+
where: {projectId: $projectId, name: $name}){
303+
%s
304+
}}""" % query.results_query_part(cls)
305+
params = {
306+
"projectId": project_id,
307+
"name": name,
308+
}
309+
response = client.execute(query_str, params)
310+
if response is None:
311+
raise labelbox.exceptions.ResourceNotFoundError(MALPredictionImport, params)
312+
313+
return response

0 commit comments

Comments
 (0)