Skip to content

Commit

Permalink
Change working directory when running notebook (#48)
Browse files Browse the repository at this point in the history
* Also remove the scripts to run and convert notebooks from model-loader
and model-trainer
  • Loading branch information
samos123 authored Oct 1, 2023
1 parent 987fd5b commit 3e7417b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
16 changes: 14 additions & 2 deletions base/scripts/run-notebook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import argparse
import sys
from pathlib import Path
import logging
Expand All @@ -9,6 +10,16 @@
from papermill.utils import merge_kwargs, remove_args
from nbconvert import HTMLExporter


parser = argparse.ArgumentParser(
prog='run-notebook.py',
description='Run a notebook and converts it to HTML while it is running')

parser.add_argument('notebook_path', help="The path to the .ipynb notebook file")
parser.add_argument('notebook_output_path', help="The path where the .ipynb notebook file should be written")
parser.add_argument('-c', '--cwd', help="Change the working directory")
args = parser.parse_args()

logging.basicConfig(level=logging.INFO, format="%(message)s")
logger.setLevel(logging.INFO)

Expand Down Expand Up @@ -68,8 +79,9 @@ def execute_notebook(

# Execute the notebook with papermill as usual
papermill.execute_notebook(
sys.argv[1],
sys.argv[2],
args.notebook_path,
args.notebook_output_path,
cwd=args.cwd,
log_output=True,
engine_name="htmlengine",
)
9 changes: 3 additions & 6 deletions base/scripts/run-notebook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ if [[ -z "$NOTEBOOK" ]]; then
for nb in /content/*.ipynb; do
[ -e "$nb" ] || continue
echo "Executing notebook $nb"
run-notebook.py "$nb" "/content/artifacts/$(basename ${nb})"
# jupyter nbconvert --to html /content/artifacts/$(basename "$nb")
run-notebook.py "$nb" "/content/artifacts/$(basename ${nb})" --cwd "$(dirname ${nb})"
done
for nb in /content/src/*.ipynb; do
[ -e "$nb" ] || continue
mkdir -p /content/artifacts/src
echo "Executing notebook $nb"
run-notebook.py "$nb" "/content/artifacts/src/$(basename ${nb})"
# jupyter nbconvert --to html /content/artifacts//src/$(basename "$nb")
run-notebook.py "$nb" "/content/artifacts/src/$(basename ${nb})" --cwd "$(dirname ${nb})"
done
else
for nb in $NOTEBOOK; do
[ -e "$nb" ] || continue
echo "Executing notebook $nb"
run-notebook.py "$nb" "/content/artifacts/$(basename ${nb})"
# jupyter nbconvert --to html /content/artifacts/$(basename "$nb")
run-notebook.py "$nb" "/content/artifacts/$(basename ${nb})" --cwd "$(dirname ${nb})"
done
fi
3 changes: 0 additions & 3 deletions model-loader-huggingface/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ RUN mkdir -p /content/model
COPY requirements.txt requirements.txt
RUN pip3 install --no-cache-dir -r requirements.txt

COPY load.sh /usr/local/bin/
COPY src/* src/

CMD load.sh
5 changes: 0 additions & 5 deletions model-loader-huggingface/load.sh

This file was deleted.

3 changes: 0 additions & 3 deletions model-trainer-huggingface/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ WORKDIR /content
COPY requirements.txt /content/requirements.txt
RUN pip install --no-cache-dir -r /content/requirements.txt

COPY scripts/* ./scripts/
COPY src/* ./src/

CMD train.sh
6 changes: 0 additions & 6 deletions model-trainer-huggingface/scripts/train.sh

This file was deleted.

0 comments on commit 3e7417b

Please sign in to comment.