Commit 4f55786d authored by ymir's avatar ymir

manage help example

parent 043084ca
......@@ -2,6 +2,5 @@
[service]
host = yggdrasil
port = 5000
port = 5001
endpoint = neuralnetwork/trainer
debug = true
Here are some examples for each possible resource and actions
***** PERCEPTRON *****
-> random
python3 neuralnetworktrainercli.py random perceptron -d 784 18 16 10 -c "random perceptron" -o /tmp/perceptron.gz
***** TRAINING SET *****
***** TRAINING SESSION *****
***** TRAINER *****
-------------------------------------------------------------
\ No newline at end of file
#!/usr/bin/env python3
# coding=utf-8
# import
from pythoncommontools.configurationLoader import configurationLoader
from os import sep
from os.path import join, realpath
from argparse import ArgumentParser
from requests import post
from json import dumps
from enum import Enum, unique
import sys
# contants
currentDirectory = realpath(__file__).rsplit(sep, 1)[0]
configurationFile=join(currentDirectory,"conf","neuralnetworktrainercli.conf")
extraHelpFile=join(currentDirectory,"help","neuralnetworktrainercli.txt")
@unique
class ContentType(Enum):
JSON = {"Content-Type": "application/json"}
GZIP = {"Content-Type": "application/gzip"}
# load configuration
configurationLoader.loadConfiguration(configurationFile)
configuration=configurationLoader.loadedConfiguration["service"]
baseURL="http://"+configuration["host"]+":"+configuration["port"]+"/"+configuration["endpoint"]
# initialize parser
parser = ArgumentParser()
parser.add_argument("action", type=str, help="the action to execute : randomize, create, read, update, delete, summarize, patch")
parser.add_argument("resource", type=str, help="the type of resource to use : perceptron, trainingset, trainingsession, trainer")
parser.add_argument("-c", "--comments", type=str, help="any free text that can help you")
parser.add_argument("-d", "--dimensions", type=int, nargs='+', help="ordered perceptrons layers sizes, i.e. 784 18 16 10")
parser.add_argument("-i", "--id", type=int, help="specific ID for the resource")
parser.add_argument("-o", "--output", type=str, help="file to write result")
# display extra help
def displayExtraHelp():
file = open(extraHelpFile, 'r')
extraHelp=file.read()
file.close()
print(extraHelp)
# check response
def checkresponse(response):
assert response.status_code==200, str(response.status_code) + " " + response.reason + " : " + response.text
# dump response
def dumpResponse(output,content):
file = open(output, "wb")
file.write(content)
file.close()
# def randomize perceptron
def randomizePerceptron(dimensions,comments,output):
URL=baseURL+"/perceptron/random"
data=dumps({"dimensions":dimensions,"comments":comments})
response = post(URL, data=data, headers=ContentType.GZIP.value)
checkresponse(response)
dumpResponse(output, response.content)
pass
# parse arguments
def dispatchRequest(arguments):
if arguments.action.upper()=="RANDOMIZE" and arguments.resource.upper()=="PERCEPTRON": randomizePerceptron(arguments.dimensions,arguments.comments,arguments.output)
pass
# run program
if __name__ == "__main__":
if len(sys.argv)==1 or sys.argv[1].upper() in ("-H","--HELP",): displayExtraHelp()
arguments = parser.parse_args()
pass
pass
......@@ -22,18 +22,18 @@ def import_submodules(package):
modules=modules+(import_submodules(full_name))
return modules
# import and parse dedicated module
import neuralnetworktrainerservice
rootPackage=neuralnetworktrainerservice
import neuralnetworktrainercli
rootPackage=neuralnetworktrainercli
modules=[rootPackage.__name__]+import_submodules (rootPackage)
print("loaded modules : " + str(modules))
# define setup parameters
setup(
name="NeuralNetworkTrainerService",
name="NeuralNetworkTrainercli",
version="0.0.0",
description="Neural network trainer CLI",
packages=modules,
#dependency_links=[YGGDRASIL_REP+"neuralnetworkcommon"],
#install_requires=["neuralnetworkcommon","psycopg2","psycopg2-binary","flask","flask_restful"],
install_requires=["requests"],
classifiers=[
'Programming Language :: Python :: 3',
],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment