lgaleana commited on
Commit
b30d7de
1 Parent(s): 2c9c198

Fix google vision key

Browse files
Files changed (2) hide show
  1. .env.example +1 -1
  2. custom_code/image_analysis.py +8 -1
.env.example CHANGED
@@ -1,2 +1,2 @@
1
  OPENAI_KEY_PERSONAL=<openai_key>
2
- GOOGLE_APPLICATION_CREDENTIALS=<gcp_key>
 
1
  OPENAI_KEY_PERSONAL=<openai_key>
2
+ GOOGLE_APPLICATION_KEY=<gcp_key_json>
custom_code/image_analysis.py CHANGED
@@ -4,22 +4,29 @@ Example prompt: write a python function that uses an api that given an image ret
4
  """
5
 
6
 
 
 
7
  from concurrent.futures import ThreadPoolExecutor
8
  from typing import Dict, List
9
 
10
  from dotenv import load_dotenv
11
  from google.cloud import vision
 
12
 
13
  from code_tasks.image_dimensions import get_image_dimensions
14
 
15
  load_dotenv()
16
 
 
 
 
 
17
 
18
  def analyze_images(images) -> List[Dict]:
19
  max = 20
20
 
21
  def get_image_info(image_url: str) -> Dict:
22
- client = vision.ImageAnnotatorClient()
23
  image = vision.Image()
24
  image.source.image_uri = image_url # type: ignore
25
 
 
4
  """
5
 
6
 
7
+ import json
8
+ import os
9
  from concurrent.futures import ThreadPoolExecutor
10
  from typing import Dict, List
11
 
12
  from dotenv import load_dotenv
13
  from google.cloud import vision
14
+ from google.oauth2 import service_account
15
 
16
  from code_tasks.image_dimensions import get_image_dimensions
17
 
18
  load_dotenv()
19
 
20
+ VISION_CREDENTIALS = service_account.Credentials.from_service_account_info(
21
+ json.loads(os.environ["GOOGLE_APPLICATION_KEY"])
22
+ )
23
+
24
 
25
  def analyze_images(images) -> List[Dict]:
26
  max = 20
27
 
28
  def get_image_info(image_url: str) -> Dict:
29
+ client = vision.ImageAnnotatorClient(credentials=VISION_CREDENTIALS)
30
  image = vision.Image()
31
  image.source.image_uri = image_url # type: ignore
32