Search code examples
pythonibm-cloudwatsonvisual-recognition

Deploying Watson Visual recognition app fails


I created some custom classifiers locally and then i try to deploy on bluemix an app that classifies an image based on the classifiers i made.

When I try to deploy it, it failes to start.

import os
import json
from os.path import join, dirname
from os import environ
from watson_developer_cloud import VisualRecognitionV3 
import time
start_time = time.time()

visual_recognition = VisualRecognitionV3(VisualRecognitionV3.latest_version, api_key='*************')

with open(join(dirname(__file__), './test170.jpg'), 'rb') as image_file:
 print(json.dumps(visual_recognition.classify(images_file=image_file,threshold=0, classifier_ids=['Angle_971786581']), indent=2))

print("--- %s seconds ---" % (time.time() - start_time))

Even if I try to deploy a simple print , it failes to deploy, but the starter app i get from bluemix, or a Flask tutorial (https://www.ibm.com/blogs/bluemix/2015/03/simple-hello-world-python-app-using-flask/) i found online deploy just fine.

I'm very new to web programming and using cloud services so i'm totally lost.

Thank you.


Solution

  • Bluemix is expecting your python application to serve on a port. If your application isn't serving some kind of response on the port, it assumes the application failed to start.

    # On Bluemix, get the port number from the environment variable PORT
    # When running this app on the local machine, default the port to 8080
    port = int(os.getenv('PORT', 8080))
    
    
    @app.route('/')
    def hello_world():
        return 'Hello World! I am running on port ' + str(port)
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', port=port)
    

    It looks like you're writing your code to just execute once and stop. Instead, make it do the work when someone hits your URL, like shown in the hello_world() function above.

    Think about what you want to happen when someone goes to YOUR_APP_NAME.mybluemix.net

    If you do not want your application to be a WEB application, but instead just execute once (a background worker application), then use the --no-route option at the end of your cf push command. Then, look at the logs using cf logs appname --recent to see the output of your application

    https://console.ng.bluemix.net/docs/manageapps/depapps.html#deployingapps