|
| 1 | +import os |
| 2 | +from pht.internal import StationRuntimeInfo, ConjunctionBuilder |
| 3 | +from pht.train.response import RunResponse |
| 4 | +from pht.train import SimpleTrain |
| 5 | +from pht.requirement import url_by_name, Require |
| 6 | +from pht.train.response.exit_state import SUCCESS |
| 7 | +from pht.rebase import DockerRebaseStrategy |
| 8 | +from pht.entrypoint import cmd_for_train |
| 9 | +import deepmedic |
| 10 | + |
| 11 | +model_file = '/opt/model' |
| 12 | + |
| 13 | + |
| 14 | +class MyTrain(SimpleTrain): |
| 15 | + def __init__(self): |
| 16 | + self.data_source = url_by_name('MY_DATA_SOURCE') |
| 17 | + |
| 18 | + # Define the requirements of the Train here |
| 19 | + def requirements(self) -> ConjunctionBuilder: |
| 20 | + return Require(self.data_source) |
| 21 | + |
| 22 | + # Generate the Summary of the Model |
| 23 | + def model_summary(self) -> str: |
| 24 | + return 'Hello from: DeepMedic' |
| 25 | + |
| 26 | + # Run the algorithm (fetch data, generate model, etc.) |
| 27 | + def run(self, info: StationRuntimeInfo) -> RunResponse: |
| 28 | + |
| 29 | + # Fetch the data here |
| 30 | + |
| 31 | + # Implement the algorithm here and serialze the learned model to the filesystem, something like this |
| 32 | + if not os.path.exists('/opt'): |
| 33 | + os.mkdir('/opt') |
| 34 | + with open(model_file, 'w') as f: |
| 35 | + f.write('Hello World') |
| 36 | + |
| 37 | + return RunResponse( |
| 38 | + state=SUCCESS, |
| 39 | + free_text_message='Hello world', |
| 40 | + rebase=DockerRebaseStrategy( |
| 41 | + frm='personalhealthtrain/train-api-python:1.0rc3', |
| 42 | + next_train_tag='station.2', |
| 43 | + export_files=[model_file] |
| 44 | + ) |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == '__main__': |
| 49 | + cmd_for_train(MyTrain()) |
0 commit comments