22from labelbase import Client as baseClient
33import pandas
44from concurrent .futures import ThreadPoolExecutor , as_completed
5+ from google .api_core import retry
56
67def create_upload_dict (df :pandas .core .frame .DataFrame , local_files :bool , lb_client :Client , base_client :baseClient , row_data_col :str ,
78 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
4546 print (f'Generated upload list - { len (global_key_to_upload_dict )} data rows to upload' )
4647 return global_key_to_upload_dict
4748
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+
4860def create_data_rows (local_files :bool , lb_client :Client , base_client :baseClient , row :pandas .core .series .Series ,
4961 metadata_name_key_to_schema :dict , metadata_schema_to_name_key :dict ,
5062 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,
6375 Returns:
6476 Two items - the global_key, and a dictionary with "row_data", "global_key", "external_id" and "metadata_fields" keys
6577 """
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 ])
6779 metadata_fields = [{"schema_id" : metadata_name_key_to_schema ['lb_integration_source' ], "value" : "Pandas" }]
6880 if metadata_index :
6981 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 ])
7482 metadata_value = base_client .process_metadata_value (
7583 metadata_value = row [metadata_field_name ],
7684 metadata_type = metadata_index [metadata_field_name ],
0 commit comments