kendrickfff commited on
Commit
e3682f7
1 Parent(s): e345a10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -7,11 +7,23 @@ from torchvision import models, transforms
7
  import json
8
  import requests
9
 
10
- # Load credentials from Hugging Face's Secret Manager
11
- hf_token = os.environ.get("HF_TOKEN") # Assuming the Hugging Face API token is set in environment
 
 
12
 
13
- # Initialize Gemini model using Hugging Face
14
- llm = ChatGoogleGenerativeAI(model='gemini-1.5-pro') # You can change 'gemini-1.5-pro' to the specific model you need
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Load a pre-trained ResNet50 model for image classification
17
  model = models.resnet50(pretrained=True)
 
7
  import json
8
  import requests
9
 
10
+ # Load credentials (stringified JSON) from environment variable
11
+ credentials_string = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
12
+ if not credentials_string:
13
+ raise ValueError("GOOGLE_APPLICATION_CREDENTIALS is not set in the environment!")
14
 
15
+ # Parse the stringified JSON back to a Python dictionary
16
+ credentials = json.loads(credentials_string)
17
+
18
+ # Save the credentials to a temporary JSON file (required by Google SDKs)
19
+ with open("service_account.json", "w") as f:
20
+ json.dump(credentials, f)
21
+
22
+ # Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the temporary file
23
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "service_account.json"
24
+
25
+ # Initialize Gemini model
26
+ llm = ChatGoogleGenerativeAI(model='gemini-1.5-pro')
27
 
28
  # Load a pre-trained ResNet50 model for image classification
29
  model = models.resnet50(pretrained=True)