We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
447 register dataset before upload pw
# 447 register dataset before upload

Closes #447.

- Adds the generated api code to register dataset uploads and uses them.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lightly/cli/upload_cli.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """**Lightly Upload:** Upload images to the Lightly platform.
3 
4 This module contains the entrypoint for the **lightly-upload**
5 command-line interface.
6 """
7 
8 # Copyright (c) 2020. Lightly AG and its affiliates.
9 # All Rights Reserved
10 import json
11 
12 import hydra
13 
14 import torchvision
15 from torch.utils.hipify.hipify_python import bcolors
16 
17 from lightly.cli._helpers import fix_input_path, print_as_warning, cpu_count
18 
19 from lightly.api.utils import getenv
20 from lightly.api.api_workflow_client import ApiWorkflowClient
21 from lightly.data import LightlyDataset
22 
23 
24 def _upload_cli(cfg, is_cli_call=True):
25     input_dir = cfg['input_dir']
26     if input_dir and is_cli_call:
27         input_dir = fix_input_path(input_dir)
28 
29     path_to_embeddings = cfg['embeddings']
30     if path_to_embeddings and is_cli_call:
31         path_to_embeddings = fix_input_path(path_to_embeddings)
32 
33     dataset_id = cfg['dataset_id']
34     token = cfg['token']
35     new_dataset_name = cfg['new_dataset_name']
36 
37     cli_api_args_wrong = False
38     if not token:
39         print_as_warning('Please specify your access token.')
40         cli_api_args_wrong = True
41 
42     dataset_id_ok = dataset_id and len(dataset_id) > 0
43     new_dataset_name_ok = new_dataset_name and len(new_dataset_name) > 0
44     if new_dataset_name_ok and not dataset_id_ok:
45         api_workflow_client = ApiWorkflowClient(token=token)
46         api_workflow_client.create_dataset(dataset_name=new_dataset_name)
47     elif dataset_id_ok and not new_dataset_name_ok:
48         api_workflow_client = ApiWorkflowClient(token=token, dataset_id=dataset_id)
49     else:
50         print_as_warning('Please specify either the dataset_id of an existing dataset or a new_dataset_name.')
51         cli_api_args_wrong = True
52 
53     if cli_api_args_wrong:
54         print_as_warning('For help, try: lightly-upload --help')
55         return
56 
57     # potentially load custom metadata
58     custom_metadata = None
59     if cfg['custom_metadata']:
60         path_to_custom_metadata = fix_input_path(cfg['custom_metadata'])
61         print(f'Loading custom metadata from {bcolors.OKBLUE}{path_to_custom_metadata}{bcolors.ENDC}')
62         with open(path_to_custom_metadata, 'r') as f:
63             custom_metadata = json.load(f)
64 
65     # determine the number of available cores
66     if cfg['loader']['num_workers'] < 0:
67         cfg['loader']['num_workers'] = cpu_count()
68 
69     size = cfg['resize']
70     if not isinstance(size, int):
71         size = tuple(size)
72     transform = None
73     if isinstance(size, tuple) or size > 0:
74         transform = torchvision.transforms.Resize(size)
75 
76     if input_dir:
77         mode = cfg['upload']
78         dataset = LightlyDataset(input_dir=input_dir, transform=transform)
79         api_workflow_client.upload_dataset(
80             input=dataset,
81             mode=mode,
82             max_workers=cfg['loader']['num_workers'],
83             custom_metadata=custom_metadata,
84         )
85         print(f"Finished the upload of the dataset.")
86 
87     if path_to_embeddings:
88         name = cfg['embedding_name']
89         print("Starting upload of embeddings.")
90         api_workflow_client.upload_embeddings(
91             path_to_embeddings_csv=path_to_embeddings, name=name
92         )
93         print("Finished upload of embeddings.")
94 
95     if new_dataset_name_ok:
96         print(f'The dataset_id of the newly created dataset is '
97               f'{bcolors.OKBLUE}{api_workflow_client.dataset_id}{bcolors.ENDC}')
98 
99 
100 @hydra.main(config_path='config', config_name='config')
101 def upload_cli(cfg):
102     """Upload images/embeddings from the command-line to the Lightly platform.
103 
104     Args:
105         cfg:
106             The default configs are loaded from the config file.
107             To overwrite them please see the section on the config file 
108             (.config.config.yaml).
109     
110     Command-Line Args:
111         input_dir:
112             Path to the input directory where images are stored.
113         embeddings:
114             Path to the csv file storing the embeddings generated by
115             lightly.
116         token:
117             User access token to the Lightly platform. If needs to be
118             specified to upload the images and embeddings to the platform.
119         dataset_id:
120             Identifier of the dataset on the Lightly platform.
121             Either the dataset_id or the new_dataset_name need to be
122             specified.
123         new_dataset_name:
124             The name of the new dataset to create on the Lightly platform.
125             Either the dataset_id or the new_dataset_name need to be
126             specified.
127         upload:
128             String to determine whether to upload the full images, 
129             thumbnails only, or metadata only.
130 
131             Must be one of ['full', 'thumbnails', 'metadata']
132         embedding_name:
133             Assign the embedding a name in order to identify it on the 
134             Lightly platform.
135         resize:
136             Desired size of the uploaded images. If negative, default size is used.
137             If size is a sequence like (h, w), output size will be matched to 
138             this. If size is an int, smaller edge of the image will be matched 
139             to this number. i.e, if height > width, then image will be rescaled
140             to (size * height / width, size).
141 
142     Examples:
143         >>> # create a new dataset on the Lightly platform and upload thumbnails to it
144         >>> lightly-upload input_dir=data/ token='123' new_dataset_name='new_dataset_name_xyz'
145         >>>
146         >>> # upload thumbnails to the Lightly platform to an existing dataset
147         >>> lightly-upload input_dir=data/ token='123' dataset_id='XYZ'
148         >>> 
149         >>> # create a new dataset on the Lightly platform and upload full images to it
150         >>> lightly-upload input_dir=data/ token='123' new_dataset_name='new_dataset_name_xyz' upload='full'
151         >>>
152         >>> # upload metadata to the Lightly platform
153         >>> lightly-upload input_dir=data/ token='123' dataset_id='XYZ' upload='metadata'
154         >>>
155         >>> # upload embeddings to the Lightly platform (must have uploaded images beforehand)
156         >>> lightly-upload embeddings=embeddings.csv token='123' dataset_id='XYZ'
157         >>>
158         >>> # upload both, images and embeddings in a single command
159         >>> lightly-upload input_dir=data/ embeddings=embeddings.csv upload='full' \\
160         >>>     token='123' dataset_id='XYZ'
161         >>> # create a new dataset on the Lightly platform and upload both, images and embeddings
162         >>> lightly-upload input_dir=data/ embeddings=embeddings.csv upload='full' \\
163         >>>     token='123' new_dataset_name='new_dataset_name_xyz'
164 
165     """
166     _upload_cli(cfg)
167 
168 
169 def entry():
170     upload_cli()
171
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lightly/cli/upload_cli.py b/lightly/cli/upload_cli.py
--- a/lightly/cli/upload_cli.py
+++ b/lightly/cli/upload_cli.py
@@ -92,6 +92,10 @@
         )
         print("Finished upload of embeddings.")
 
+    if custom_metadata is not None and not input_dir:
+        # upload custom metadata separately
+        api_workflow_client.upload_custom_metadata(custom_metadata, verbose=True)
+
     if new_dataset_name_ok:
         print(f'The dataset_id of the newly created dataset is '
               f'{bcolors.OKBLUE}{api_workflow_client.dataset_id}{bcolors.ENDC}')

{"golden_diff": "diff --git a/lightly/cli/upload_cli.py b/lightly/cli/upload_cli.py\n--- a/lightly/cli/upload_cli.py\n+++ b/lightly/cli/upload_cli.py\n@@ -92,6 +92,10 @@\n         )\n         print(\"Finished upload of embeddings.\")\n \n+    if custom_metadata is not None and not input_dir:\n+        # upload custom metadata separately\n+        api_workflow_client.upload_custom_metadata(custom_metadata, verbose=True)\n+\n     if new_dataset_name_ok:\n         print(f'The dataset_id of the newly created dataset is '\n               f'{bcolors.OKBLUE}{api_workflow_client.dataset_id}{bcolors.ENDC}')\n", "issue": "447 register dataset before upload pw\n# 447 register dataset before upload\r\n\r\nCloses #447.\r\n\r\n- Adds the generated api code to register dataset uploads and uses them.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"**Lightly Upload:** Upload images to the Lightly platform.\n\nThis module contains the entrypoint for the **lightly-upload**\ncommand-line interface.\n\"\"\"\n\n# Copyright (c) 2020. Lightly AG and its affiliates.\n# All Rights Reserved\nimport json\n\nimport hydra\n\nimport torchvision\nfrom torch.utils.hipify.hipify_python import bcolors\n\nfrom lightly.cli._helpers import fix_input_path, print_as_warning, cpu_count\n\nfrom lightly.api.utils import getenv\nfrom lightly.api.api_workflow_client import ApiWorkflowClient\nfrom lightly.data import LightlyDataset\n\n\ndef _upload_cli(cfg, is_cli_call=True):\n    input_dir = cfg['input_dir']\n    if input_dir and is_cli_call:\n        input_dir = fix_input_path(input_dir)\n\n    path_to_embeddings = cfg['embeddings']\n    if path_to_embeddings and is_cli_call:\n        path_to_embeddings = fix_input_path(path_to_embeddings)\n\n    dataset_id = cfg['dataset_id']\n    token = cfg['token']\n    new_dataset_name = cfg['new_dataset_name']\n\n    cli_api_args_wrong = False\n    if not token:\n        print_as_warning('Please specify your access token.')\n        cli_api_args_wrong = True\n\n    dataset_id_ok = dataset_id and len(dataset_id) > 0\n    new_dataset_name_ok = new_dataset_name and len(new_dataset_name) > 0\n    if new_dataset_name_ok and not dataset_id_ok:\n        api_workflow_client = ApiWorkflowClient(token=token)\n        api_workflow_client.create_dataset(dataset_name=new_dataset_name)\n    elif dataset_id_ok and not new_dataset_name_ok:\n        api_workflow_client = ApiWorkflowClient(token=token, dataset_id=dataset_id)\n    else:\n        print_as_warning('Please specify either the dataset_id of an existing dataset or a new_dataset_name.')\n        cli_api_args_wrong = True\n\n    if cli_api_args_wrong:\n        print_as_warning('For help, try: lightly-upload --help')\n        return\n\n    # potentially load custom metadata\n    custom_metadata = None\n    if cfg['custom_metadata']:\n        path_to_custom_metadata = fix_input_path(cfg['custom_metadata'])\n        print(f'Loading custom metadata from {bcolors.OKBLUE}{path_to_custom_metadata}{bcolors.ENDC}')\n        with open(path_to_custom_metadata, 'r') as f:\n            custom_metadata = json.load(f)\n\n    # determine the number of available cores\n    if cfg['loader']['num_workers'] < 0:\n        cfg['loader']['num_workers'] = cpu_count()\n\n    size = cfg['resize']\n    if not isinstance(size, int):\n        size = tuple(size)\n    transform = None\n    if isinstance(size, tuple) or size > 0:\n        transform = torchvision.transforms.Resize(size)\n\n    if input_dir:\n        mode = cfg['upload']\n        dataset = LightlyDataset(input_dir=input_dir, transform=transform)\n        api_workflow_client.upload_dataset(\n            input=dataset,\n            mode=mode,\n            max_workers=cfg['loader']['num_workers'],\n            custom_metadata=custom_metadata,\n        )\n        print(f\"Finished the upload of the dataset.\")\n\n    if path_to_embeddings:\n        name = cfg['embedding_name']\n        print(\"Starting upload of embeddings.\")\n        api_workflow_client.upload_embeddings(\n            path_to_embeddings_csv=path_to_embeddings, name=name\n        )\n        print(\"Finished upload of embeddings.\")\n\n    if new_dataset_name_ok:\n        print(f'The dataset_id of the newly created dataset is '\n              f'{bcolors.OKBLUE}{api_workflow_client.dataset_id}{bcolors.ENDC}')\n\n\n@hydra.main(config_path='config', config_name='config')\ndef upload_cli(cfg):\n    \"\"\"Upload images/embeddings from the command-line to the Lightly platform.\n\n    Args:\n        cfg:\n            The default configs are loaded from the config file.\n            To overwrite them please see the section on the config file \n            (.config.config.yaml).\n    \n    Command-Line Args:\n        input_dir:\n            Path to the input directory where images are stored.\n        embeddings:\n            Path to the csv file storing the embeddings generated by\n            lightly.\n        token:\n            User access token to the Lightly platform. If needs to be\n            specified to upload the images and embeddings to the platform.\n        dataset_id:\n            Identifier of the dataset on the Lightly platform.\n            Either the dataset_id or the new_dataset_name need to be\n            specified.\n        new_dataset_name:\n            The name of the new dataset to create on the Lightly platform.\n            Either the dataset_id or the new_dataset_name need to be\n            specified.\n        upload:\n            String to determine whether to upload the full images, \n            thumbnails only, or metadata only.\n\n            Must be one of ['full', 'thumbnails', 'metadata']\n        embedding_name:\n            Assign the embedding a name in order to identify it on the \n            Lightly platform.\n        resize:\n            Desired size of the uploaded images. If negative, default size is used.\n            If size is a sequence like (h, w), output size will be matched to \n            this. If size is an int, smaller edge of the image will be matched \n            to this number. i.e, if height > width, then image will be rescaled\n            to (size * height / width, size).\n\n    Examples:\n        >>> # create a new dataset on the Lightly platform and upload thumbnails to it\n        >>> lightly-upload input_dir=data/ token='123' new_dataset_name='new_dataset_name_xyz'\n        >>>\n        >>> # upload thumbnails to the Lightly platform to an existing dataset\n        >>> lightly-upload input_dir=data/ token='123' dataset_id='XYZ'\n        >>> \n        >>> # create a new dataset on the Lightly platform and upload full images to it\n        >>> lightly-upload input_dir=data/ token='123' new_dataset_name='new_dataset_name_xyz' upload='full'\n        >>>\n        >>> # upload metadata to the Lightly platform\n        >>> lightly-upload input_dir=data/ token='123' dataset_id='XYZ' upload='metadata'\n        >>>\n        >>> # upload embeddings to the Lightly platform (must have uploaded images beforehand)\n        >>> lightly-upload embeddings=embeddings.csv token='123' dataset_id='XYZ'\n        >>>\n        >>> # upload both, images and embeddings in a single command\n        >>> lightly-upload input_dir=data/ embeddings=embeddings.csv upload='full' \\\\\n        >>>     token='123' dataset_id='XYZ'\n        >>> # create a new dataset on the Lightly platform and upload both, images and embeddings\n        >>> lightly-upload input_dir=data/ embeddings=embeddings.csv upload='full' \\\\\n        >>>     token='123' new_dataset_name='new_dataset_name_xyz'\n\n    \"\"\"\n    _upload_cli(cfg)\n\n\ndef entry():\n    upload_cli()\n", "path": "lightly/cli/upload_cli.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"**Lightly Upload:** Upload images to the Lightly platform.\n\nThis module contains the entrypoint for the **lightly-upload**\ncommand-line interface.\n\"\"\"\n\n# Copyright (c) 2020. Lightly AG and its affiliates.\n# All Rights Reserved\nimport json\n\nimport hydra\n\nimport torchvision\nfrom torch.utils.hipify.hipify_python import bcolors\n\nfrom lightly.cli._helpers import fix_input_path, print_as_warning, cpu_count\n\nfrom lightly.api.utils import getenv\nfrom lightly.api.api_workflow_client import ApiWorkflowClient\nfrom lightly.data import LightlyDataset\n\n\ndef _upload_cli(cfg, is_cli_call=True):\n    input_dir = cfg['input_dir']\n    if input_dir and is_cli_call:\n        input_dir = fix_input_path(input_dir)\n\n    path_to_embeddings = cfg['embeddings']\n    if path_to_embeddings and is_cli_call:\n        path_to_embeddings = fix_input_path(path_to_embeddings)\n\n    dataset_id = cfg['dataset_id']\n    token = cfg['token']\n    new_dataset_name = cfg['new_dataset_name']\n\n    cli_api_args_wrong = False\n    if not token:\n        print_as_warning('Please specify your access token.')\n        cli_api_args_wrong = True\n\n    dataset_id_ok = dataset_id and len(dataset_id) > 0\n    new_dataset_name_ok = new_dataset_name and len(new_dataset_name) > 0\n    if new_dataset_name_ok and not dataset_id_ok:\n        api_workflow_client = ApiWorkflowClient(token=token)\n        api_workflow_client.create_dataset(dataset_name=new_dataset_name)\n    elif dataset_id_ok and not new_dataset_name_ok:\n        api_workflow_client = ApiWorkflowClient(token=token, dataset_id=dataset_id)\n    else:\n        print_as_warning('Please specify either the dataset_id of an existing dataset or a new_dataset_name.')\n        cli_api_args_wrong = True\n\n    if cli_api_args_wrong:\n        print_as_warning('For help, try: lightly-upload --help')\n        return\n\n    # potentially load custom metadata\n    custom_metadata = None\n    if cfg['custom_metadata']:\n        path_to_custom_metadata = fix_input_path(cfg['custom_metadata'])\n        print(f'Loading custom metadata from {bcolors.OKBLUE}{path_to_custom_metadata}{bcolors.ENDC}')\n        with open(path_to_custom_metadata, 'r') as f:\n            custom_metadata = json.load(f)\n\n    # determine the number of available cores\n    if cfg['loader']['num_workers'] < 0:\n        cfg['loader']['num_workers'] = cpu_count()\n\n    size = cfg['resize']\n    if not isinstance(size, int):\n        size = tuple(size)\n    transform = None\n    if isinstance(size, tuple) or size > 0:\n        transform = torchvision.transforms.Resize(size)\n\n    if input_dir:\n        mode = cfg['upload']\n        dataset = LightlyDataset(input_dir=input_dir, transform=transform)\n        api_workflow_client.upload_dataset(\n            input=dataset,\n            mode=mode,\n            max_workers=cfg['loader']['num_workers'],\n            custom_metadata=custom_metadata,\n        )\n        print(f\"Finished the upload of the dataset.\")\n\n    if path_to_embeddings:\n        name = cfg['embedding_name']\n        print(\"Starting upload of embeddings.\")\n        api_workflow_client.upload_embeddings(\n            path_to_embeddings_csv=path_to_embeddings, name=name\n        )\n        print(\"Finished upload of embeddings.\")\n\n    if custom_metadata is not None and not input_dir:\n        # upload custom metadata separately\n        api_workflow_client.upload_custom_metadata(custom_metadata, verbose=True)\n\n    if new_dataset_name_ok:\n        print(f'The dataset_id of the newly created dataset is '\n              f'{bcolors.OKBLUE}{api_workflow_client.dataset_id}{bcolors.ENDC}')\n\n\n@hydra.main(config_path='config', config_name='config')\ndef upload_cli(cfg):\n    \"\"\"Upload images/embeddings from the command-line to the Lightly platform.\n\n    Args:\n        cfg:\n            The default configs are loaded from the config file.\n            To overwrite them please see the section on the config file \n            (.config.config.yaml).\n    \n    Command-Line Args:\n        input_dir:\n            Path to the input directory where images are stored.\n        embeddings:\n            Path to the csv file storing the embeddings generated by\n            lightly.\n        token:\n            User access token to the Lightly platform. If needs to be\n            specified to upload the images and embeddings to the platform.\n        dataset_id:\n            Identifier of the dataset on the Lightly platform.\n            Either the dataset_id or the new_dataset_name need to be\n            specified.\n        new_dataset_name:\n            The name of the new dataset to create on the Lightly platform.\n            Either the dataset_id or the new_dataset_name need to be\n            specified.\n        upload:\n            String to determine whether to upload the full images, \n            thumbnails only, or metadata only.\n\n            Must be one of ['full', 'thumbnails', 'metadata']\n        embedding_name:\n            Assign the embedding a name in order to identify it on the \n            Lightly platform.\n        resize:\n            Desired size of the uploaded images. If negative, default size is used.\n            If size is a sequence like (h, w), output size will be matched to \n            this. If size is an int, smaller edge of the image will be matched \n            to this number. i.e, if height > width, then image will be rescaled\n            to (size * height / width, size).\n\n    Examples:\n        >>> # create a new dataset on the Lightly platform and upload thumbnails to it\n        >>> lightly-upload input_dir=data/ token='123' new_dataset_name='new_dataset_name_xyz'\n        >>>\n        >>> # upload thumbnails to the Lightly platform to an existing dataset\n        >>> lightly-upload input_dir=data/ token='123' dataset_id='XYZ'\n        >>> \n        >>> # create a new dataset on the Lightly platform and upload full images to it\n        >>> lightly-upload input_dir=data/ token='123' new_dataset_name='new_dataset_name_xyz' upload='full'\n        >>>\n        >>> # upload metadata to the Lightly platform\n        >>> lightly-upload input_dir=data/ token='123' dataset_id='XYZ' upload='metadata'\n        >>>\n        >>> # upload embeddings to the Lightly platform (must have uploaded images beforehand)\n        >>> lightly-upload embeddings=embeddings.csv token='123' dataset_id='XYZ'\n        >>>\n        >>> # upload both, images and embeddings in a single command\n        >>> lightly-upload input_dir=data/ embeddings=embeddings.csv upload='full' \\\\\n        >>>     token='123' dataset_id='XYZ'\n        >>> # create a new dataset on the Lightly platform and upload both, images and embeddings\n        >>> lightly-upload input_dir=data/ embeddings=embeddings.csv upload='full' \\\\\n        >>>     token='123' new_dataset_name='new_dataset_name_xyz'\n\n    \"\"\"\n    _upload_cli(cfg)\n\n\ndef entry():\n    upload_cli()\n", "path": "lightly/cli/upload_cli.py"}]}