Skip to content

A simple interface that creates very basic http server with python to connect between python project like a ML model and JS clients or servers for demo purposes, DON'T USE IN PRODUCTION

Notifications You must be signed in to change notification settings

hrr2000/client-python-basic-interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

client-python-basic-interface

A simple interface that creates a very basic http server in python to connect between your python project like an Machine Learning model and JS clients or servers for demo purposes, DON'T USE IN PRODUCTION

How To Use

  • Put the 3 files any where in your project.
  • Open use.py file
  • You will find a TestModel class, feel free to edit or remove it, It's just an example how you can use the script.
  • Write your own class and extend it from BaseMLModel and override run() function with your logic like calling your model function
# your function 
def myfunc(name):
    return "Hello " + name
    
# your class 
class TestModel(BaseMLModel):

    # **kwargs contains all parameters you have sent from your client.    
    def run(self, **kwargs):
        return myfunc(name=kwargs['name']) # call your function
  • Just run python server.py and you will see Server started http://localhost:8080 and you can stop it by interrupting the command.
  • You are done now.

Client side

  • You can call the host main endpoint and it supports only 1 POST request with.
  • model_name string parameter which contains the exact name of your class
  • data in a JSON form.
  • Or just use the client function in the MLInterface.js file. in HTML
<script src="MLInterface.js"></script>
<script>
  runModel('TestModel', {
    name: "Mostafa"
  }).then((result) => {
    console.log(result)
  })
</script>

Change port

  • You can change your default port if you have a conflict from server.py file.
# ...
# basic server

HOSTNAME = "localhost"
PORT = 8080
# ...

About

A simple interface that creates very basic http server with python to connect between python project like a ML model and JS clients or servers for demo purposes, DON'T USE IN PRODUCTION

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published