phyloforfun commited on
Commit
01e6026
1 Parent(s): a03d740

Major update. Support for 15 LLMs, World Flora Online taxonomy validation, geolocation, 2 OCR methods, significant UI changes, stability improvements, consistent JSON parsing

Browse files
vouchervision/OCR_google_cloud_vision.py CHANGED
@@ -1,4 +1,4 @@
1
- import os, io, sys, inspect, statistics
2
  from statistics import mean
3
  # from google.cloud import vision, storage
4
  from google.cloud import vision
@@ -6,6 +6,7 @@ from google.cloud import vision_v1p3beta1 as vision_beta
6
  from PIL import Image, ImageDraw, ImageFont
7
  import colorsys
8
  from tqdm import tqdm
 
9
 
10
  currentdir = os.path.dirname(os.path.abspath(
11
  inspect.getfile(inspect.currentframe())))
@@ -254,7 +255,18 @@ class OCRGoogle:
254
 
255
 
256
  def detect_text(self):
257
- client = vision.ImageAnnotatorClient()
 
 
 
 
 
 
 
 
 
 
 
258
  with io.open(self.path, 'rb') as image_file:
259
  content = image_file.read()
260
  image = vision.Image(content=content)
@@ -369,7 +381,19 @@ class OCRGoogle:
369
 
370
 
371
  def detect_handwritten_ocr(self):
372
- client = vision_beta.ImageAnnotatorClient()
 
 
 
 
 
 
 
 
 
 
 
 
373
  with open(self.path, "rb") as image_file:
374
  content = image_file.read()
375
 
 
1
+ import os, io, sys, inspect, statistics, json
2
  from statistics import mean
3
  # from google.cloud import vision, storage
4
  from google.cloud import vision
 
6
  from PIL import Image, ImageDraw, ImageFont
7
  import colorsys
8
  from tqdm import tqdm
9
+ from google.oauth2 import service_account
10
 
11
  currentdir = os.path.dirname(os.path.abspath(
12
  inspect.getfile(inspect.currentframe())))
 
255
 
256
 
257
  def detect_text(self):
258
+ service_account_json_str = os.getenv('google_service_account_json')
259
+ if not service_account_json_str:
260
+ print("Service account JSON not found in environment variables.")
261
+ return False
262
+
263
+ # Convert JSON string to a dictionary
264
+ service_account_info = json.loads(service_account_json_str)
265
+ # Create credentials from the service account info
266
+ credentials = service_account.Credentials.from_service_account_info(service_account_info)
267
+ # Initialize the client with the credentials
268
+ client = vision.ImageAnnotatorClient(credentials=credentials)
269
+ # client = vision.ImageAnnotatorClient() #####################################################################################################################
270
  with io.open(self.path, 'rb') as image_file:
271
  content = image_file.read()
272
  image = vision.Image(content=content)
 
381
 
382
 
383
  def detect_handwritten_ocr(self):
384
+ service_account_json_str = os.getenv('google_service_account_json')
385
+ if not service_account_json_str:
386
+ print("Service account JSON not found in environment variables.")
387
+ return False
388
+
389
+ # Convert JSON string to a dictionary
390
+ service_account_info = json.loads(service_account_json_str)
391
+ # Create credentials from the service account info
392
+ credentials = service_account.Credentials.from_service_account_info(service_account_info)
393
+ # Initialize the client with the credentials
394
+ client = vision.ImageAnnotatorClient(credentials=credentials)
395
+ # client = vision.ImageAnnotatorClient() #####################################################################################################################
396
+
397
  with open(self.path, "rb") as image_file:
398
  content = image_file.read()
399