2
2
from labelbase import Client as baseClient
3
3
import pandas
4
4
from concurrent .futures import ThreadPoolExecutor , as_completed
5
+ from google .api_core import retry
5
6
6
7
def create_upload_dict (df :pandas .core .frame .DataFrame , local_files :bool , lb_client :Client , base_client :baseClient , row_data_col :str ,
7
8
global_key_col :str = "" , external_id_col :str = "" , metadata_index :dict = {}, divider :str = "///" , verbose = False ):
@@ -45,6 +46,17 @@ def create_upload_dict(df:pandas.core.frame.DataFrame, local_files:bool, lb_clie
45
46
print (f'Generated upload list - { len (global_key_to_upload_dict )} data rows to upload' )
46
47
return global_key_to_upload_dict
47
48
49
+ @retry .Retry (predicate = retry .if_exception_type (Exception ), deadline = 120. )
50
+ def create_file (lb_client , file_path :str ):
51
+ """ Wraps lb_client.upload_file() in retry logic
52
+ Args:
53
+ lb_client : Required (labelbox.client.Client) - Labelbox Client object
54
+ file_path : Required (str) - String corresponding to the row data file path
55
+ Returns:
56
+ Temporary URL to-be-uploaded to Labelbox
57
+ """
58
+ return lb_client .upload_file (file_path )
59
+
48
60
def create_data_rows (local_files :bool , lb_client :Client , base_client :baseClient , row :pandas .core .series .Series ,
49
61
metadata_name_key_to_schema :dict , metadata_schema_to_name_key :dict ,
50
62
row_data_col :str , global_key_col :str = "" , external_id_col :str = "" , metadata_index :dict = {}, divider :str = "///" ):
@@ -63,14 +75,10 @@ def create_data_rows(local_files:bool, lb_client:Client, base_client:baseClient,
63
75
Returns:
64
76
Two items - the global_key, and a dictionary with "row_data", "global_key", "external_id" and "metadata_fields" keys
65
77
"""
66
- row_data = lb_client . upload_file (str (row [row_data_col ])) if local_files else str (row [row_data_col ])
78
+ row_data = create_file (str (row [row_data_col ])) if local_files else str (row [row_data_col ])
67
79
metadata_fields = [{"schema_id" : metadata_name_key_to_schema ['lb_integration_source' ], "value" : "Pandas" }]
68
80
if metadata_index :
69
81
for metadata_field_name in metadata_index .keys ():
70
- print (type (row ))
71
- print (metadata_field_name )
72
- print (type (row [metadata_field_name ]))
73
- print (row [metadata_field_name ])
74
82
metadata_value = base_client .process_metadata_value (
75
83
metadata_value = row [metadata_field_name ],
76
84
metadata_type = metadata_index [metadata_field_name ],
0 commit comments