Skip to content

Commit 9bfaa63

Browse files
committed
cleanup so we do not need eto unpack response
1 parent ebb0844 commit 9bfaa63

File tree

3 files changed

+220
-10
lines changed

3 files changed

+220
-10
lines changed

labelbox/schema/batch.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,8 @@ def export_data_rows(self,
110110
response = requests.get(download_url)
111111
response.raise_for_status()
112112
reader = ndjson.reader(StringIO(response.text))
113-
return (Entity.DataRow(
114-
self.client, {
115-
**result, 'customMetadata': result['metadata'],
116-
'metadataFields': result['metadataFields']
117-
}) for result in reader)
113+
return (
114+
Entity.DataRow(self.client, result) for result in reader)
118115
elif res["status"] == "FAILED":
119116
raise LabelboxError("Data row export failed.")
120117

labelbox/schema/dataset.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,8 @@ def export_data_rows(self,
495495
response = requests.get(download_url)
496496
response.raise_for_status()
497497
reader = ndjson.reader(StringIO(response.text))
498-
return (Entity.DataRow(
499-
self.client, {
500-
**result, 'customMetadata': result['metadata'],
501-
'metadataFields': result['metadataFields']
502-
}) for result in reader)
498+
return (
499+
Entity.DataRow(self.client, result) for result in reader)
503500
elif res["status"] == "FAILED":
504501
raise LabelboxError("Data row export failed.")
505502

test.py

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
from json import tool
2+
from xml.etree.ElementInclude import include
3+
from labelbox import Client, Project
4+
import time
5+
from labelbox.data.serialization import NDJsonConverter, LBV1Converter
6+
import os
7+
import requests
8+
from datetime import datetime, timezone
9+
from pprint import pprint
10+
from labelbox.orm.db_object import experimental
11+
from labelbox.schema.data_row import DataRow
12+
13+
from labelbox.schema.data_row_metadata import (
14+
DataRowMetadata,
15+
DataRowMetadataField,
16+
DeleteDataRowMetadata,
17+
)
18+
19+
import uuid
20+
# import re
21+
import json
22+
from dataclasses import dataclass, field
23+
from labelbox import Tool, Classification
24+
from typing import List
25+
26+
from labelbox.schema.ontology import OntologyBuilder
27+
28+
from labelbox.schema.annotation_import import LabelImport
29+
# from labelbox.schema.bulk_import_request import DataRow
30+
from labelbox.schema.labeling_frontend import LabelingFrontend
31+
from labelbox.schema.ontology import Classification, OntologyBuilder, Ontology, Tool, Option
32+
from labelbox import Label
33+
34+
# from labelbox.data.annotation_types.classification import ClassificationAnswer, Dropdown, Text, Radio
35+
# from labelbox.data.metrics.confusion_matrix import feature_confusion_matrix_metric, confusion_matrix_metric
36+
# from labelbox.data.annotation_types import ObjectAnnotation, ClassificationAnnotation, TextEntity, Mask
37+
# import numpy as np
38+
# from labelbox.data.serialization.labelbox_v1.label import LBV1LabelAnnotationsVideo
39+
40+
import logging
41+
# logging.basicConfig(level=logging.DEBUG)
42+
43+
44+
# __________________________________________
45+
def cleanup_my_org():
46+
from datetime import datetime, timezone
47+
48+
date = datetime.strptime("2022-06-01",
49+
"%Y-%m-%d").replace(tzinfo=timezone.utc)
50+
51+
for project in client.get_projects():
52+
if project.created_at > date:
53+
print(project.name)
54+
project.delete()
55+
for dataset in client.get_datasets():
56+
if dataset.created_at > date:
57+
print(dataset.name)
58+
dataset.delete()
59+
for model in client.get_models():
60+
model.delete()
61+
62+
63+
os.system('clear')
64+
65+
# API_KEY = os.environ.get('apikey')
66+
# client = Client(API_KEY, enable_experimental=True)
67+
68+
69+
# API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbDN1OXJ3NzIwMDlvMHl4a2ViOHhkdml0Iiwib3JnYW5pemF0aW9uSWQiOiJjbDN1OXJ3Nm4wMDluMHl4azYzczVnNjZwIiwiYXBpS2V5SWQiOiJjbDU4YWhsaHEwYzR0MHkxZjhsYzc4NWxzIiwic2VjcmV0IjoiZTdlZjg5NTE2YjExNjQ5ZDE2MGQ1MTQxMGU1ZGUwYzIiLCJpYXQiOjE2NTcwMzI3MDQsImV4cCI6MjI4ODE4NDcwNH0.uQeS5xWVokFx5qQb-IXEgTnYnDfg_sH3jGUNd5Mw8Zc"
70+
# client = Client(API_KEY, endpoint="https://api.lb-stage.xyz/graphql")
71+
72+
# print(client.get_organization())
73+
74+
#Python SDK Staging API Key 2
75+
76+
77+
78+
79+
API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbDI5M2N2OWUwMDBicnRvdTBneWgyZ3RvIiwib3JnYW5pemF0aW9uSWQiOiJjbDI5M2N2NjAwMDBhcnRvdTl0M3JhMGpzIiwiYXBpS2V5SWQiOiJjbDN2c21icWgwMDBhbjdvdWFldWMwMmcyIiwic2VjcmV0IjoiYTQ4MmZjODU4OGU5YmI0NmJhZDU2YjljZDBhZDcyZTUiLCJpYXQiOjE2NTQxMDAzMTUsImV4cCI6MjI4NTI1MjMxNX0.UJC2uF8Cu6WwBSIZGUZUY8UznP7RCRsG4ns616OFXjI"
80+
client = Client(API_KEY, endpoint='http://localhost:8080/graphql')
81+
82+
# API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbDN1OXJ3NzIwMDlvMHl4a2ViOHhkdml0Iiwib3JnYW5pemF0aW9uSWQiOiJjbDN1OXJ3Nm4wMDluMHl4azYzczVnNjZwIiwiYXBpS2V5SWQiOiJjbDUxZWxxd3EwMGphMHl3MTZpMWdhdmdyIiwic2VjcmV0IjoiOWFlN2E1MjhiM2JkNjY2N2ZiNThhNTU4NzMwYzc3MjYiLCJpYXQiOjE2NTY2MTYzNTMsImV4cCI6MjI4Nzc2ODM1M30.Ej8Gk01QSpAV-55UEUIxiKV5Glu1uu_BryOQwBxc9HM"
83+
# client = Client(API_KEY, endpoint="https://api.lb-stage.xyz/graphql")
84+
85+
start = time.time()
86+
project = client.get_project("cl5cwcz57000ae2ou1aoi9gld") #test queued data rows
87+
# rows = project.export_queued_data_rows(include_metadata=True)
88+
89+
# dataset = client.get_dataset("cl3w2r147000qj6ou307h4045")
90+
# rows = dataset.export_data_rows(include_metadata=True)
91+
92+
# project.update(queue_mode=Project.QueueMode.Batch)
93+
# batch_rows = [row['id'] for row in project.export_queued_data_rows()][:5000]
94+
# batch = project.create_batch(name="hello world", data_rows=batch_rows)
95+
# print(batch.uid)
96+
batch = list(project.batches())[0]
97+
# rows = batch.export_data_rows(include_metadata=True)
98+
rows = batch.export_data_rows()
99+
#batch id is ae4dbe30-03c3-11ed-8a4d-870387097bd0
100+
101+
end = time.time()
102+
print(f"{end-start} seconds")
103+
# print(labels[-1])
104+
count = 0
105+
MAXIMUM = 5
106+
for row in rows:
107+
# print(row.media_attributes, "\t\t", row.metadata, "\n")
108+
print(row,"\n")
109+
count +=1
110+
if count > MAXIMUM:
111+
break
112+
# Label.bulk_delete([label for label in project.labels()])
113+
114+
115+
116+
117+
# [print(f"""\n
118+
# {label['Media Attributes']},
119+
# {label['DataRow ID']},
120+
# {label['DataRow Metadata']}
121+
# """) for label in labels]
122+
# bbox = [0,1,2,3]
123+
# annotations = []
124+
125+
# for datarow in project.export_queued_data_rows():
126+
# annotations.append({
127+
# "uuid": str(uuid.uuid4()),
128+
# "name": "bbox",
129+
# "dataRow": {
130+
# "id": datarow['id']
131+
# },
132+
# "bbox": {
133+
# "left": bbox[0],
134+
# "top": bbox[1],
135+
# "height": bbox[2],
136+
# "width": bbox[3]
137+
# }
138+
# })
139+
140+
# import_annotations = LabelImport.create_from_objects(client=client, project_id = project.uid, name=f"import {str(uuid.uuid4())}", labels=annotations)
141+
# import_annotations.wait_until_done()
142+
# print("\nthis is complete")
143+
144+
145+
146+
# ____________________________________________________________________________________
147+
148+
# editor = next(client.get_labeling_frontends(where = LabelingFrontend.name == 'editor'))
149+
150+
151+
# alt = {
152+
# "tools": [
153+
# {
154+
# "tool": "polygon",
155+
# "name": "jyjyjyy33",
156+
# "color": "#1CE6FF",
157+
# "label": "pgon",
158+
# "classifications": []
159+
# },
160+
# {
161+
# "tool": "rectangle",
162+
# "name": "jyjyjyy33",
163+
# "color": "#FF34FF",
164+
# "label": "bbox",
165+
# "classifications": [
166+
# {
167+
# "type": "radio",
168+
# "name": "radio_sub",
169+
# "instructions": "radio sub",
170+
# "options": [
171+
# {
172+
# "value": "ans_1",
173+
# "label": "ans 1",
174+
# "options": []
175+
# },
176+
# {
177+
# "value": "ans_12",
178+
# "label": "ans 12",
179+
# "options": []
180+
# }
181+
# ]
182+
# },
183+
# {
184+
# "type": "text",
185+
# "name": "text_sub",
186+
# "instructions": "text sub",
187+
# "uiMode": "hotkey",
188+
# "options": []
189+
# }
190+
# ]
191+
# },
192+
# {
193+
# "tool": "polygon",
194+
# "name": "pgon",
195+
# "color": "#FF4A46",
196+
# "label": "pgon",
197+
# "classifications": []
198+
# }
199+
# ],
200+
# "relationships": [],
201+
# "classifications": [
202+
# {
203+
# "type": "text",
204+
# "name": "bbox",
205+
# "instructions": "bbox",
206+
# "uiMode": "hotkey",
207+
# "scope": "global",
208+
# "options": []
209+
# }
210+
# ],
211+
# }
212+
# project.setup(editor, alt)
213+
214+
215+
216+

0 commit comments

Comments
 (0)