我正在开发 Java Web 应用程序,我正在尝试使用一种简单的 AI 算法 - NLP 来解析文本。 我想从我的应用程序 NLP.py 运行一个 python 脚本,它使用来 self 本地 pc 上的另一个文件(3 Gb 大小)的数据,我下载了 python 插件并像这样运行脚本:
String pythonScriptPath = "MY-PATH\\NLP\\NLP.py";
String[] cmd = new String[3];
cmd[0] = "python"; // check version of installed python: python -V
cmd[1] = pythonScriptPath;
cmd[2]="playing sport";
// create runtime to execute external command
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
文件层次结构:
现在我想在 Azure 上运行所有这些东西,我没有找到任何相关教程,我将应用程序部署为常规 Web 应用程序但我仍然不知道:
- 将脚本使用的文件上传到哪里?
- 要写什么路径而不是 MY-PATH?
- python 脚本将如何在 Azure 上运行,我应该使用什么资源 使用以及如何使用?
- 它会像这样工作吗(作为使用 python 插件的网络应用程序)或 我应该做一些完全不同的事情吗?
请您参考如下方法:
1.Where to upload the file that the script uses ?
我建议您在您的 Azure 应用程序项目中创建一个新文件夹,例如 D:\home\site\wwwroot\ProcessFile。
但是,Azure Web 应用文件系统存储受您的应用服务限制。 (您可以在门户网站上查看)因此,如果您的文件太大,您需要将它们存储到 Azure 存储中。
2.What path to write instead of MY-PATH ?
按照上面的绝对路径D:\home\site\wwwroot\ProcessFile\NLP.py
3.How will the python script run on Azure, what resource should I use and how?
据我所知,Azure Web App 有自己的 Python 环境,但你无权更改它。由于您使用的NLP涉及依赖包,所以我建议您安装Python Extension。
具体步骤请按照我之前回答过的案例
1. install odbc driver to azure app service
安装包后,您需要更改代码中的路径参数。
String python= "D:\home\python362x86\python.exe";
String pythonScriptPath = "D:\home\site\wwwroot\ProcessFile\NLP.py";
String[] cmd = new String[3];
cmd[0] = "python"; // check version of installed python: python -V
cmd[1] = pythonScriptPath;
cmd[2]="playing sport";
// create runtime to execute external command
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
希望对你有帮助。如有任何疑虑,请随时告诉我。
