Skip to content

Commit

Permalink
feat: add cli to push to hf (#19)
Browse files Browse the repository at this point in the history
* feat: add cli to push to hf

* fix: fix cli

* fix: fix readme
  • Loading branch information
samsja authored Aug 11, 2023
1 parent 5d1eed9 commit 7d5d18d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ Once the file are generated you can postprocess the files and save it into a jso
python dataset_gen_cli.py filter ./exercises dataset.jsonl
```

push to hf dataset

```shell
python dataset_gen_cli.py push "jinaai/code_exercises_40k" dataset.jsonl
```
15 changes: 15 additions & 0 deletions textbook/dataset_gen/dataset_gen_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from textbook.dataset_gen.create_prompts import Topic, Query
from textbook.dataset_gen.filtering import load_and_filter_exos
from datasets import Dataset

app = Typer()

Expand Down Expand Up @@ -127,5 +128,19 @@ def filter(exo_path: Path, dataset_file: str):
write_results_to_jsonl(dataset_file, exos)


@app.command()
def push(repo_name: str, dataset_file: Path):
with open(dataset_file, "r") as file:
lines = file.readlines()
exercises = [json.loads(line) for line in lines]

def gen():
for exo in exercises:
yield exo

dataset = Dataset.from_generator(gen)
dataset.push_to_hub(repo_name)


if __name__ == "__main__":
app()

0 comments on commit 7d5d18d

Please sign in to comment.