gpt4 book ai didi

java - 将使用 python 脚本的 Java Web 应用程序部署到 Azure

转载 作者:太空宇宙 更新时间:2023-11-04 02:26:08 25 4
gpt4 key购买 nike

我正在开发 Java Web 应用程序,我正在尝试使用简单的 AI 算法 - NLP 来解析文本。我想从我的应用程序 NLP.py 运行一个 python 脚本,该脚本使用驻留在本地电脑上的另一个文件(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);

文件层次结构:

files hierarchy

现在我想在 Azure 上运行所有这些东西,我没有找到任何相关教程,我将应用程序部署为常规 Web 应用程序,但我仍然不知道:

  1. 在哪里上传脚本使用的文件?
  2. 用什么路径代替 MY-PATH ?
  3. Python 脚本如何在 Azure 上运行,我应该使用什么资源使用方法以及如何使用?
  4. 它会像这样工作吗(作为使用 python 插件的网络应用程序)或者我应该做一些完全不同的事情吗?

最佳答案

1.Where to upload the file that the script uses ?

我建议您在 Azure 应用程序项目中创建一个新文件夹,例如 D:\home\site\wwwroot\ProcessFile

enter image description here

但是,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扩展

具体步骤请按照我之前回答过的案例进行。

1. install odbc driver to azure app service

2. pyodbc on Azure

安装软件包后,您需要更改代码中的路径参数。

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

希望对您有帮助。如有任何疑问,请随时告诉我。

关于java - 将使用 python 脚本的 Java Web 应用程序部署到 Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50370810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com