Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,10 +19,33 @@ openai = OpenAI(api_key = openai.api_key)
|
|
| 19 |
|
| 20 |
class GPTDriveIntegration:
|
| 21 |
def __init__(self):
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
scopes=['https://www.googleapis.com/auth/drive.readonly']
|
| 25 |
)
|
|
|
|
| 26 |
self.drive_service = build('drive', 'v3', credentials=self.credentials)
|
| 27 |
|
| 28 |
# Initialize OpenAI
|
|
|
|
| 19 |
|
| 20 |
class GPTDriveIntegration:
|
| 21 |
def __init__(self):
|
| 22 |
+
credentials_info = {
|
| 23 |
+
"type": "service_account",
|
| 24 |
+
"project_id": os.getenv('GOOGLE_PROJECT_ID'),
|
| 25 |
+
"private_key_id": os.getenv('GOOGLE_PRIVATE_KEY_ID'),
|
| 26 |
+
"private_key": os.getenv('GOOGLE_PRIVATE_KEY').replace('\\n', '\n'), # Fix line breaks
|
| 27 |
+
"client_email": os.getenv('GOOGLE_CLIENT_EMAIL'),
|
| 28 |
+
"client_id": os.getenv('GOOGLE_CLIENT_ID'),
|
| 29 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 30 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 31 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 32 |
+
"client_x509_cert_url": os.getenv('GOOGLE_CLIENT_CERT_URL'),
|
| 33 |
+
"universe_domain": "googleapis.com"
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Check if all required fields are present
|
| 37 |
+
required_fields = ['project_id', 'private_key', 'client_email']
|
| 38 |
+
missing_fields = [field for field in required_fields if not credentials_info[field]]
|
| 39 |
+
|
| 40 |
+
if missing_fields:
|
| 41 |
+
raise ValueError(f"Missing required environment variables: {missing_fields}")
|
| 42 |
+
|
| 43 |
+
# Initialize Google Drive API
|
| 44 |
+
self.credentials = service_account.Credentials.from_service_account_info(
|
| 45 |
+
credentials_info,
|
| 46 |
scopes=['https://www.googleapis.com/auth/drive.readonly']
|
| 47 |
)
|
| 48 |
+
|
| 49 |
self.drive_service = build('drive', 'v3', credentials=self.credentials)
|
| 50 |
|
| 51 |
# Initialize OpenAI
|