Rithvickkr commited on
Commit
cbb56ac
·
1 Parent(s): 556e727

Add GCP credentials handling and temporary file storage

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -7,7 +7,24 @@ from google.cloud import aiplatform
7
  from transformers import pipeline
8
  from google.genai import types
9
  import gradio as gr
10
- import os, json
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  apikey = "AIzaSyCeY0ji2gnMwvP8jGCU_Z5DG6m9Ybo3JeE" # Replace or use os.getenv if secret
 
7
  from transformers import pipeline
8
  from google.genai import types
9
  import gradio as gr
10
+ import os, tempfile
11
+ import json
12
+ from google.cloud import aiplatform
13
+
14
+ creds_json = os.getenv("GCP_CREDS_JSON")
15
+ if not creds_json:
16
+ raise Exception("⚠️ Missing GCP_CREDS_JSON secret!")
17
+
18
+ # Save to temp file
19
+ with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmpfile:
20
+ tmpfile.write(creds_json)
21
+ creds_path = tmpfile.name
22
+
23
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = creds_path
24
+
25
+ # Initialize GCP API
26
+ aiplatform.init(project="your-project-id", location="us-central1")
27
+
28
 
29
 
30
  apikey = "AIzaSyCeY0ji2gnMwvP8jGCU_Z5DG6m9Ybo3JeE" # Replace or use os.getenv if secret