Update app.py
Browse files
app.py
CHANGED
@@ -13,12 +13,10 @@ from google.oauth2 import service_account
|
|
13 |
# Upload credential json file from default compute service account
|
14 |
#os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "herbaria-ai-3c860bcb0f44.json"
|
15 |
|
16 |
-
credentials_raw = os.environ.get("
|
17 |
-
|
18 |
-
|
19 |
credentials_json = json.loads(credentials_raw)
|
20 |
-
|
21 |
-
# Use the parsed credentials to create a service account
|
22 |
credentials = service_account.Credentials.from_service_account_info(credentials_json)
|
23 |
|
24 |
# Global DataFrame declaration
|
@@ -35,12 +33,9 @@ def translate_text(text, target_language="en"):
|
|
35 |
return result["translatedText"]
|
36 |
|
37 |
def batch_process_documents(file_path: str, file_mime_type: str) -> tuple:
|
38 |
-
|
39 |
-
# Initialize Document AI client with credentials
|
40 |
-
client_options = {'credentials': credentials}
|
41 |
|
42 |
-
client = documentai.DocumentProcessorServiceClient(client_options=
|
43 |
-
#client = documentai.DocumentProcessorServiceClient(client_options=opts)
|
44 |
|
45 |
with open(file_path, "rb") as file_stream:
|
46 |
raw_document = RawDocument(content=file_stream.read(), mime_type=file_mime_type)
|
|
|
13 |
# Upload credential json file from default compute service account
|
14 |
#os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "herbaria-ai-3c860bcb0f44.json"
|
15 |
|
16 |
+
credentials_raw = os.environ.get("GOOGLE_CREDENTIALS")
|
17 |
+
if not credentials_raw:
|
18 |
+
raise EnvironmentError("Google Cloud credentials not found in environment.")
|
19 |
credentials_json = json.loads(credentials_raw)
|
|
|
|
|
20 |
credentials = service_account.Credentials.from_service_account_info(credentials_json)
|
21 |
|
22 |
# Global DataFrame declaration
|
|
|
33 |
return result["translatedText"]
|
34 |
|
35 |
def batch_process_documents(file_path: str, file_mime_type: str) -> tuple:
|
36 |
+
opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com", credentials=credentials)
|
|
|
|
|
37 |
|
38 |
+
client = documentai.DocumentProcessorServiceClient(client_options=opts)
|
|
|
39 |
|
40 |
with open(file_path, "rb") as file_stream:
|
41 |
raw_document = RawDocument(content=file_stream.read(), mime_type=file_mime_type)
|