How can I convert a python program into a web service?
You could use raw sockets in your Python and php programs to make them communicate through TCP locally. 
Make your Python program a TCP server with address 'localhost' and port number, for example, 5555, and then, in your php script, also using sockets, create a client code that sends the to be processed text as a TCP request to your Python script.
I have a python program. It takes some text from a text file (A) as an input, do some text annotation and stores the annotated text as an output in another file (B). Now, my plan was to make this like a web service.
I could do this using php and calling the python program from php. Specifically, my php code does this-
--Takes text from a HTML textarea.
--Saves the text into file A.
--Runs the python program.
--Load the output from file B and show the annotated text in the HTML textarea.
Now, to do the text annotation, python program needs to load a model from another big file (C). I would say, loading time is 10 sec and annotating takes 2 sec. Each time, I have a new text in the HTML textarea, I need 12 sec to show the output. I want to minimize the overall time.
I was thinking, if I could communicate from PHP with an already running python program, I could actually save 10 sec. Because, then python would just need to load the model file C once and it could apply the model on any text that PHP sends him and it could send the output to PHP too.
Is there a way I can achieve this? Can django help here in anyway?
Thank you for reading so much.