@@ -22,28 +22,34 @@ def screen_pdf_file(
2222 project_id : str ,
2323 location_id : str ,
2424 template_id : str ,
25- pdf_content_base64 : str ,
25+ pdf_content_filename : str ,
2626) -> modelarmor_v1 .SanitizeUserPromptResponse :
2727 """Sanitize/Screen PDF text content using the Model Armor API.
2828
2929 Args:
3030 project_id (str): Google Cloud project ID.
3131 location_id (str): Google Cloud location.
3232 template_id (str): The template ID used for sanitization.
33- pdf_content_base64 (str): PDF data in base64 format .
33+ pdf_content_filename (str): Path to a PDF file .
3434
3535 Returns:
3636 SanitizeUserPromptResponse: The sanitized user prompt response.
3737 """
3838 # [START modelarmor_screen_pdf_file]
3939
40+ import base64
4041 from google .api_core .client_options import ClientOptions
4142 from google .cloud import modelarmor_v1
4243
4344 # TODO(Developer): Uncomment these variables.
4445 # project_id = "YOUR_PROJECT_ID"
4546 # location_id = "us-central1"
4647 # template_id = "template_id"
48+ # pdf_content_filename = "path/to/file.pdf"
49+
50+ # Encode the PDF file into base64
51+ with open (pdf_content_filename , "rb" ) as f :
52+ pdf_content_base64 = base64 .b64encode (f .read ())
4753
4854 # Create the Model Armor client.
4955 client = modelarmor_v1 .ModelArmorClient (
0 commit comments