Skip to content

Commit

Permalink
Watson languages support #4, #11.
Browse files Browse the repository at this point in the history
  • Loading branch information
28mm committed Mar 2, 2017
1 parent c0e3ba2 commit bf67646
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 18 additions & 2 deletions bin/fovea.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,16 @@ def main():
faces=args.faces)

elif args.provider == 'watson':
if args.lang not in Watson.label_langs:
raise

query = Watson(image,
WATSON_CV_URL,
WATSON_CV_KEY,
labels=args.labels,
categories=args.categories,
faces=args.faces)
faces=args.faces,
label_lang=args.lang)

elif args.provider == 'clarifai':
# Make sure we have sane language defaults
Expand Down Expand Up @@ -933,14 +937,21 @@ def tabular(self, confidence=0.0):

class Watson(Query):

def __init__(self, image, api_url, api_key, labels=True, categories=False, faces=False):
# supported classifier/tag languages
label_langs = [ 'en', # (English)
'es', # (Spanish)
'ar', # (Arabic)
'ja' ] # (Japanese)

def __init__(self, image, api_url, api_key, labels=True, categories=False, faces=False, label_lang='en'):
self.api_url = api_url
self.api_key = api_key
self.image = image
self._labels = labels
self._categories = categories
self._faces = faces
self._json = None
self.label_lang = label_lang

def run(self):

Expand All @@ -960,6 +971,10 @@ def run(self):
'version' : '2016-05-20'
}

headers = {
'Accept-Language' : self.label_lang
}

f = BytesFile(self.image, filename=image_fname)


Expand All @@ -968,6 +983,7 @@ def run(self):
url = self.api_url + '/v3/classify'
response = requests.post(url,
params=params,
headers=headers,
files={ 'images_file' :
(f.name, f, image_mime) })

Expand Down
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Fovea provides a standardized tabular output mode, suitable for interactive shel
| Feature | Google | Microsoft | Amazon | Clarifai | Watson | OpenCV | Tabular | JSON |
| ---: | --- | --- | --- | --- | --- | --- | --- | --- |
| Labels | ✅️️ | ✅ ️️ | ✅️️ ||| | ✅ ️️| ✅ ️️|
| Label Translations | || ||| |||
| Faces | ✅️️ | ✅️️ | ✅️️ ||| ✅️️ | ✅️️ | ✅️️ |
| Landmarks | ✅ ️| | | | | | ✅️️ | ✅️ ️|
| Text (OCR) || ✅️️️ | | | | | ️️❌ | ✅️️ |
Expand All @@ -25,8 +26,6 @@ Fovea provides a standardized tabular output mode, suitable for interactive shel
| Image Type | | ✅️ | | | | || ✅️ ️|
| Color | | ✅️️ | || | || ✅️️ |
| Celebrities | || ||| |||
| Languages | || ||| |||
| Languages (OCR) ||| | | | |||

## Installation and Setup

Expand Down

0 comments on commit bf67646

Please sign in to comment.