Skip to content

Commit

Permalink
:feat(GDPR): request/ response support
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdsouza committed Apr 17, 2018
1 parent 018af9c commit 48c80e4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 117 deletions.
Binary file modified .env.enc
Binary file not shown.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ python:
- '3.6'
cache: pip
before_install:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_6e98b3e8e789_key -iv $encrypted_6e98b3e8e789_iv -in .env.enc -out .env -d || true'
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_cebf25e6c525_key
-iv $encrypted_cebf25e6c525_iv -in .env.enc -out .env -d || true'
install: pip install tox-travis
script:
- pip install -U python-dotenv
Expand Down
5 changes: 2 additions & 3 deletions examples/visual_recognition_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'/ginni_bio_780x981_v4_03162016.jpg'

visual_recognition = VisualRecognitionV3('2016-05-20', api_key='YOUR API KEY')
classifier_id = 'CarsvsTrucksxDO_NOT_DELETE_771019274'

# with open(join(dirname(__file__), '../resources/cars.zip'), 'rb') as cars, \
# open(join(dirname(__file__), '../resources/trucks.zip'), 'rb') as
Expand All @@ -19,7 +18,7 @@

car_path = join(dirname(__file__), '../resources/cars.zip')
with open(car_path, 'rb') as images_file:
parameters = json.dumps({'threshold': 0.1, 'classifier_ids': [classifier_id, 'default']})
parameters = json.dumps({'threshold': 0.1, 'classifier_ids': ['default']})
car_results = visual_recognition.classify(images_file=images_file,
parameters=parameters)
print(json.dumps(car_results, indent=2))
Expand All @@ -30,7 +29,7 @@
car_results = visual_recognition.classify(
images_file=images_file,
threshold='0.1',
classifier_ids=[classifier_id, 'default'])
classifier_ids=['default'])
print(json.dumps(car_results, indent=2))
except WatsonApiException as ex:
print(ex.httpResponse.json())
Expand Down
Binary file added resources/dog.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 21 additions & 15 deletions test/integration/test_visual_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@
@pytest.mark.skipif(
os.getenv('VCAP_SERVICES') is None, reason='requires VCAP_SERVICES')
class IntegrationTestVisualRecognitionV3(TestCase):
def setUp(self):
self.visual_recognition = watson_developer_cloud.VisualRecognitionV3(
visual_recognition = None
classifier_id = None

@classmethod
def setup_class(cls):
cls.visual_recognition = watson_developer_cloud.VisualRecognitionV3(
'2016-05-20', api_key=os.environ.get('YOUR API KEY'))
self.visual_recognition.set_default_headers({
cls.visual_recognition.set_default_headers({
'X-Watson-Learning-Opt-Out':
'1',
'X-Watson-Test':
'1'
})
self.classifier_id = 'CarsvsTrucksxDO_NOT_DELETE_771019274'

@classmethod
def teardown_class(cls):
classifiers = cls.visual_recognition.list_classifiers()['classifiers']

if classifiers:
for classifier in classifiers:
if 'CarsVsTrucks' in classifier['name']:
cls.visual_recognition.delete_classifier(classifier['classifier_id'])

def test_classify(self):
car_path = join(dirname(__file__), '../../resources/cars.zip')
car_path = join(dirname(__file__), '../../resources/dog.jpg')
with open(car_path, 'rb') as images_file:
parameters = json.dumps({
'threshold':
0.1,
'classifier_ids': [self.classifier_id, 'default']
})
car_results = self.visual_recognition.classify(
images_file=images_file, parameters=parameters)
images_file=images_file,
threshold='0.1',
classifier_ids=['default'])
assert car_results is not None

def test_detect_faces(self):
Expand All @@ -45,7 +54,7 @@ def test_custom_classifier(self):
with open(os.path.join(os.path.dirname(__file__), '../../resources/cars.zip'), 'rb') as cars, \
open(os.path.join(os.path.dirname(__file__), '../../resources/trucks.zip'), 'rb') as trucks:
classifier = self.visual_recognition.create_classifier(
'Cars vs Trucks',
'CarsVsTrucks',
cars_positive_examples=cars,
negative_examples=trucks,
)
Expand All @@ -56,9 +65,6 @@ def test_custom_classifier(self):
output = self.visual_recognition.get_classifier(classifier_id)
assert output is not None

classifiers = self.visual_recognition.list_classifiers()
assert classifiers is not None

output = self.visual_recognition.delete_classifier(classifier_id)

def test_core_ml_model(self):
Expand Down
Loading

0 comments on commit 48c80e4

Please sign in to comment.