@@ -22,28 +22,34 @@ def screen_pdf_file(
22
22
project_id : str ,
23
23
location_id : str ,
24
24
template_id : str ,
25
- pdf_content_base64 : str ,
25
+ pdf_content_filename : str ,
26
26
) -> modelarmor_v1 .SanitizeUserPromptResponse :
27
27
"""Sanitize/Screen PDF text content using the Model Armor API.
28
28
29
29
Args:
30
30
project_id (str): Google Cloud project ID.
31
31
location_id (str): Google Cloud location.
32
32
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 .
34
34
35
35
Returns:
36
36
SanitizeUserPromptResponse: The sanitized user prompt response.
37
37
"""
38
38
# [START modelarmor_screen_pdf_file]
39
39
40
+ import base64
40
41
from google .api_core .client_options import ClientOptions
41
42
from google .cloud import modelarmor_v1
42
43
43
44
# TODO(Developer): Uncomment these variables.
44
45
# project_id = "YOUR_PROJECT_ID"
45
46
# location_id = "us-central1"
46
47
# 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 ())
47
53
48
54
# Create the Model Armor client.
49
55
client = modelarmor_v1 .ModelArmorClient (
0 commit comments