0

我在本地创建了一些自定义分类器,然后尝试在 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/)我发现在线部署很好。

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

谢谢你。

4

3 回答 3

3

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

于 2016-11-26T19:44:55.090 回答
0

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

watson_developer_cloud

然后,requirements.txt 就像这样:

Flask==0.10.1
watson_developer_cloud
于 2017-02-24T01:31:17.550 回答
0

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

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

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

于 2016-11-28T10:09:35.620 回答