Aniket2012 commited on
Commit
36d932b
·
verified ·
1 Parent(s): 1d9c98f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -74,6 +74,47 @@ import json
74
  import uuid
75
  import os
76
  import re
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  from typing import Dict, Any
78
  import gradio as gr
79
  import vertexai
 
74
  import uuid
75
  import os
76
  import re
77
+ import sys
78
+ import subprocess
79
+ from typing import Dict, Any, List
80
+
81
+ # Setup Logging
82
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
83
+
84
+
85
+
86
+
87
+ def check_gcloud_auth():
88
+ """Checks for GCP authentication and provides instructions if missing."""
89
+ try:
90
+ # The 'gcloud auth print-access-token' command is a reliable way to check for active credentials.
91
+ # We capture stderr to suppress the verbose output on success.
92
+ subprocess.check_output("gcloud auth application-default print-access-token", shell=True, stderr=subprocess.DEVNULL)
93
+ logging.info("GCP authentication credentials found.")
94
+ return True
95
+ except subprocess.CalledProcessError:
96
+ error_message = """
97
+ ================================================================================
98
+ CRITICAL ERROR: Google Cloud Authentication Not Found!
99
+ ================================================================================
100
+ This application requires authentication to access Google Cloud services (Vertex AI, Cloud Storage).
101
+
102
+ To fix this, please run the following command in your terminal and follow the prompts to log in with your Google account:
103
+
104
+ gcloud auth application-default login
105
+
106
+ After authenticating, please restart this Python script.
107
+ ================================================================================
108
+ """
109
+ print(error_message, file=sys.stderr)
110
+ return False
111
+
112
+ # Run the auth check before trying to import heavy libraries
113
+ if not check_gcloud_auth():
114
+ sys.exit(1)
115
+
116
+
117
+
118
  from typing import Dict, Any
119
  import gradio as gr
120
  import vertexai