2

I am working on java web application and I'm trying to use a simple AI algorithm - NLP to parse texts. I want to run a python script from my app NLP.py which uses a data from another file (3 Gb size) that resides on my local pc, I downloaded the python plugin and I run the script like this:

   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:

files hierarchy

Now I want to run all these things on Azure, I didn't find any relevant tutorial, I deployed the app as a regular web app but I still don't know:

  1. Where to upload the file that the script uses ?
  2. What path to write instead of MY-PATH ?
  3. How will the python script run on Azure, what resource should I use and how?
  4. Will it work like this (as web app that uses a python plugin) or should I do something entirely different?
akshat
  • 1,219
  • 1
  • 8
  • 24

1 Answers1

2

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

I suggest you creating a new folder in your azure app project, such as D:\home\site\wwwroot\ProcessFile.

enter image description here

However, azure web app file system storage is limited by your app service. (You could check it on the portal) So, if your files are too large, you need to storage them into Azure Storage.

2.What path to write instead of MY-PATH ?

Just follow above absolute path D:\home\site\wwwroot\ProcessFile\NLP.py

3.How will the python script run on Azure, what resource should I use and how?

Per my knowledge, Azure Web App has its own Python environment, but you don't have permission to change it. Since you're using NLP which involves dependency packages, so I suggest you installing the Python Extension.

About details about steps , please follow the cases I answered before.

1.install odbc driver to azure app service

2.pyodbc on Azure

After installing your packages,you need to change the path parameters in your code.

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

Hope it helps you. Any concern ,please feel free to let me know.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • I will let you know if I'll have any further questions. Thank you very very much for this great detailed answer! – Mohamed Taher May 18 '18 at 12:04
  • Hi Jay Gong, I tried to upload the file that the script uses to a new folder in my Azure app project as you explained, but it didn't upload, that happened probably because of the size of the file, can you explain how to add the file to Azure storage account and what is the path for it in this way? Thank you very much! – Mohamed Taher May 22 '18 at 13:30