@@ -27,77 +27,70 @@ def create_instruction(project_id, data_type, instruction_gcs_uri):
2727 Google Cloud Storage.
2828 """
2929 from google .cloud import datalabeling_v1beta1 as datalabeling
30+
3031 client = datalabeling .DataLabelingServiceClient ()
3132 # [END datalabeling_create_instruction_beta]
3233 # If provided, use a provided test endpoint - this will prevent tests on
3334 # this snippet from triggering any action by a real human
34- if ' DATALABELING_ENDPOINT' in os .environ :
35- opts = ClientOptions (api_endpoint = os .getenv (' DATALABELING_ENDPOINT' ))
35+ if " DATALABELING_ENDPOINT" in os .environ :
36+ opts = ClientOptions (api_endpoint = os .getenv (" DATALABELING_ENDPOINT" ))
3637 client = datalabeling .DataLabelingServiceClient (client_options = opts )
3738 # [START datalabeling_create_instruction_beta]
3839
39- project_path = client . project_path ( project_id )
40+ project_path = f"projects/ { project_id } "
4041
41- pdf_instruction = datalabeling .types .PdfInstruction (
42- gcs_file_uri = instruction_gcs_uri )
42+ pdf_instruction = datalabeling .PdfInstruction (gcs_file_uri = instruction_gcs_uri )
4343
44- instruction = datalabeling .types . Instruction (
45- display_name = ' YOUR_INSTRUCTION_DISPLAY_NAME' ,
46- description = ' YOUR_DESCRIPTION' ,
44+ instruction = datalabeling .Instruction (
45+ display_name = " YOUR_INSTRUCTION_DISPLAY_NAME" ,
46+ description = " YOUR_DESCRIPTION" ,
4747 data_type = data_type ,
48- pdf_instruction = pdf_instruction
48+ pdf_instruction = pdf_instruction ,
4949 )
5050
51- operation = client .create_instruction (project_path , instruction )
51+ operation = client .create_instruction (
52+ request = {"parent" : project_path , "instruction" : instruction }
53+ )
5254
5355 result = operation .result ()
5456
5557 # The format of the resource name:
5658 # project_id/{project_id}/instruction/{instruction_id}
57- print ('The instruction resource name: {}' .format (result .name ))
58- print ('Display name: {}' .format (result .display_name ))
59- print ('Description: {}' .format (result .description ))
60- print ('Create time:' )
61- print ('\t seconds: {}' .format (result .create_time .seconds ))
62- print ('\t nanos: {}' .format (result .create_time .nanos ))
63- print ('Data type: {}' .format (
64- datalabeling .enums .DataType (result .data_type ).name ))
65- print ('Pdf instruction:' )
66- print ('\t Gcs file uri: {}\n ' .format (
67- result .pdf_instruction .gcs_file_uri ))
59+ print ("The instruction resource name: {}" .format (result .name ))
60+ print ("Display name: {}" .format (result .display_name ))
61+ print ("Description: {}" .format (result .description ))
62+ print ("Create time:" )
63+ print ("\t seconds: {}" .format (result .create_time .timestamp_pb ().seconds ))
64+ print ("\t nanos: {}" .format (result .create_time .timestamp_pb ().nanos ))
65+ print ("Data type: {}" .format (datalabeling .DataType (result .data_type ).name ))
66+ print ("Pdf instruction:" )
67+ print ("\t Gcs file uri: {}\n " .format (result .pdf_instruction .gcs_file_uri ))
6868
6969 return result
70+
71+
7072# [END datalabeling_create_instruction_beta]
7173
7274
73- if __name__ == ' __main__' :
75+ if __name__ == " __main__" :
7476 parser = argparse .ArgumentParser (
75- description = __doc__ ,
76- formatter_class = argparse .RawDescriptionHelpFormatter
77+ description = __doc__ , formatter_class = argparse .RawDescriptionHelpFormatter
7778 )
7879
79- parser .add_argument (
80- '--project-id' ,
81- help = 'Project ID. Required.' ,
82- required = True
83- )
80+ parser .add_argument ("--project-id" , help = "Project ID. Required." , required = True )
8481
8582 parser .add_argument (
86- ' --data-type' ,
87- help = ' Data type. Only support IMAGE, VIDEO, TEXT and AUDIO. Required.' ,
88- required = True
83+ " --data-type" ,
84+ help = " Data type. Only support IMAGE, VIDEO, TEXT and AUDIO. Required." ,
85+ required = True ,
8986 )
9087
9188 parser .add_argument (
92- ' --instruction-gcs-uri' ,
93- help = ' The URI of Google Cloud Storage of the instruction. Required.' ,
94- required = True
89+ " --instruction-gcs-uri" ,
90+ help = " The URI of Google Cloud Storage of the instruction. Required." ,
91+ required = True ,
9592 )
9693
9794 args = parser .parse_args ()
9895
99- create_instruction (
100- args .project_id ,
101- args .data_type ,
102- args .instruction_gcs_uri
103- )
96+ create_instruction (args .project_id , args .data_type , args .instruction_gcs_uri )
0 commit comments