部署 Watson Visual 识别应用程序失败

Deploying Watson Visual recognition app fails

我在本地创建了一些自定义分类器,然后我尝试在 bluemix 上部署一个应用程序,该应用程序根据我创建的分类器对图像进行分类。

当我尝试部署它时,它无法启动。

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))

即使我尝试部署一个简单的 print ,它也无法部署,但是我从 bluemix 获得的入门应用程序或 Flask 教程 (https://www.ibm.com/blogs/bluemix/2015/03/simple-hello-world-python-app-using-flask/) 我发现在线部署很好。

我对网络编程和使用云服务还很陌生,所以我完全迷路了。

谢谢。

Bluemix 期待您的 python 应用程序在端口上提供服务。如果您的应用程序没有在端口上提供某种响应,它会假定应用程序无法启动。

# 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)

看起来您编写的代码只执行一次然后停止。相反,让它在有人点击您的 URL 时完成工作,如上面的 hello_world() 函数所示。

想想当有人去 YOUR_APP_NAME.mybluemix.net

时你希望发生什么

如果您不希望您的应用程序成为 WEB 应用程序,而是只执行一次(后台工作程序应用程序),请在 cf push 命令末尾使用 --no-route 选项。然后,使用 cf logs appname --recent 查看日志以查看应用程序的输出

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

主要问题是 watson-developer-cloud 模块,给我一个无法找到的错误。

我降级到 python 版本 2.7.12,为所有用户安装。 修改了 runtime.exe 和 requirments.txt(requirments.txt 可能不需要) 与 Diego 一起上演,使用 no-route 和 set-health-check APP_NAME none 命令。

那些解决了问题,但我仍然得到退出状态 0。

当您在 bluemix 中部署应用程序时,您应该有一个 requirements.txt,其中包括您在应用程序中使用的服务。 所以,你应该检查你的 requirements.txt,也许你丢失了

watson_developer_cloud

然后,requirements.txt 喜欢这个:

Flask==0.10.1
watson_developer_cloud