Skip to content

Commit

Permalink
Merge pull request #55 from h1st-ai/cli-replace-script-with-notebook
Browse files Browse the repository at this point in the history
replace modeling script with notebook
  • Loading branch information
nqbao authored Oct 1, 2020
2 parents 0feb950 + 7a2ca9b commit 59e41f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 38 deletions.
5 changes: 2 additions & 3 deletions h1st/cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ def new_project(project_name, base_path):
model_file=f"{model_package}.py",
)

with open(tmppath / f"{project_name_snake_case}_modeling.py", "w") as f:
f.write(_render_template('modeling', {
'SCRIPT_NAME': f'{project_name_snake_case}_modeling.py',
with open(tmppath / f"{project_name_snake_case}_notebook.ipynb", "w") as f:
f.write(_render_template('notebook', {
'MODEL_CLASS': model_name,
'MODEL_PACKAGE': model_package,
}))
Expand Down
35 changes: 5 additions & 30 deletions h1st/cli/templates/notebook.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"### H1st Configuration ###\n",
"'''\n",
"This part configures the default variable names for various step of the modelling process.\n",
"Modify with care.\n",
"'''\n",
"VAR_MODEL_FILE = '$$MODEL_FILE$$.py'\n",
"VAR_MODEL = 'm'\n",
"VAR_LOADED_DATA = 'loaded_data'\n",
"VAR_PREPARED_DATA = 'prepared_data'\n",
"VAR_PREDICTED_VALUE = 'predicted_val'\n",
"\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 3\n",
"import h1st as h1\n",
"h1.init()\n",
"### End H1st Configuration ###"
"from $$MODEL_PACKAGE$$ import $$MODEL_CLASS$$"
]
},
{
Expand All @@ -31,8 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"from $$PACKAGE_NAME$$.models.$$MODEL_FILE$$ import $$MODEL_NAME$$ \n",
"m = $$MODEL_NAME$$()"
"m = $$MODEL_CLASS$$()"
]
},
{
Expand Down Expand Up @@ -70,8 +53,7 @@
"metadata": {},
"outputs": [],
"source": [
"eval_data = {} # Load evaluation data\n",
"m.evaluate(eval_data)"
"m.evaluate(prepared_data)"
]
},
{
Expand All @@ -89,16 +71,9 @@
"metadata": {},
"outputs": [],
"source": [
"predict_data = {} # Get your data \n",
"predicted_val = m.predict(predict_data)"
"input_data = {} # Get your data \n",
"m.predict(input_data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
8 changes: 8 additions & 0 deletions h1st/model_repository/model_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ def get_model_repo(cls, ref=None):
except ModuleNotFoundError:
repo_path = None

# in the new structure, the config file may be at root folder
if not repo_path:
try:
import config
repo_path = config.MODEL_REPO_PATH
except ModuleNotFoundError:
repo_path = None

if not repo_path:
repo_path = os.environ.get('H1ST_MODEL_REPO_PATH', '')

Expand Down
5 changes: 0 additions & 5 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ def test_cli_smoketest(self):
cwd=tmpdir + '/AutoCyber',
)

subprocess.check_call(
["python", "auto_cyber_modeling.py"],
cwd=tmpdir + '/AutoCyber',
)

subprocess.check_call(
["python", "-m", "models.model2"],
cwd=tmpdir + '/AutoCyber'
Expand Down

0 comments on commit 59e41f7

Please sign in to comment.