Spaces:
Running
Running
kendrickfff
commited on
Commit
•
e3682f7
1
Parent(s):
e345a10
Update app.py
Browse files
app.py
CHANGED
@@ -7,11 +7,23 @@ from torchvision import models, transforms
|
|
7 |
import json
|
8 |
import requests
|
9 |
|
10 |
-
# Load credentials
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|