Skip to content

Commit

Permalink
Generate notebooks for all languages (huggingface#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewtun authored Sep 13, 2022
1 parent 2c0b3ba commit 5536b4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ python -m pip install -r requirements.txt
Then run the following script:

```bash
python utils/generate_notebooks.py --language LANG-ID --output_dir nbs
python utils/generate_notebooks.py --output_dir nbs
```

This script extracts all the code snippets from the chapters associated with `chapters/LANG-ID` and stores them as notebooks in the `nbs` folder (which is ignored by Git by default).
This script extracts all the code snippets from the chapters and stores them as notebooks in the `nbs` folder (which is ignored by Git by default).

## ✍️ Contributing a new chapter

Expand Down
12 changes: 10 additions & 2 deletions utils/generate_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

frameworks = {"pt": "PyTorch", "tf": "TensorFlow"}

PATH_TO_COURSE = Path("chapters/")


def read_and_split_frameworks(fname):
"""
Expand Down Expand Up @@ -269,8 +271,14 @@ def create_notebooks(language, output_dir):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--language", type=str, default="en", help="Path to the course MDX files")
parser.add_argument("--output_dir", type=str, help="Where to output the notebooks")
args = parser.parse_args()

create_notebooks(args.language, args.output_dir)
languages = [f.stem for f in PATH_TO_COURSE.iterdir() if f.is_dir()]

for language in languages:
language_output_dir = f"{args.output_dir}/{language}"
create_notebooks(language, language_output_dir)
# Remove empty notebook folders
if not any(Path(language_output_dir).iterdir()):
shutil.rmtree(language_output_dir)

0 comments on commit 5536b4a

Please sign in to comment.