diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-01-07 16:51:38 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-01-07 16:51:38 +0100 |
| commit | 151ade996065ad02c2d96b723c94589066491d54 (patch) | |
| tree | b89377beed63d343ba44a833ade7c483a2b8d78c /cli/app/commands/cortex | |
| parent | 7ea77a044ca9de9d8089bf382640fb4a7bfabc0f (diff) | |
upload bytesio object to cortex
Diffstat (limited to 'cli/app/commands/cortex')
| -rw-r--r-- | cli/app/commands/cortex/upload.py | 15 | ||||
| -rw-r--r-- | cli/app/commands/cortex/upload_bytes.py | 33 |
2 files changed, 48 insertions, 0 deletions
diff --git a/cli/app/commands/cortex/upload.py b/cli/app/commands/cortex/upload.py new file mode 100644 index 0000000..c1b0a46 --- /dev/null +++ b/cli/app/commands/cortex/upload.py @@ -0,0 +1,15 @@ +import click + +from app.utils.cortex_utils import upload_to_cortex + +@click.command('') +@click.option('-i', '--input', 'opt_fp_in', required=True, + help='Path to input image') +@click.option('-f', '--folder_id', 'opt_folder_id', required=True, + help='ID of folder on Cortex') +@click.pass_context +def cli(ctx, opt_fp_in, opt_folder_id): + """ + Test uploading a file to Cortex + """ + upload_to_cortex(opt_folder_id, opt_fp_in) diff --git a/cli/app/commands/cortex/upload_bytes.py b/cli/app/commands/cortex/upload_bytes.py new file mode 100644 index 0000000..5260b8e --- /dev/null +++ b/cli/app/commands/cortex/upload_bytes.py @@ -0,0 +1,33 @@ +import click + +import numpy as np +from PIL import Image +from io import BytesIO +from app.utils.cortex_utils import upload_bytes_to_cortex + +@click.command('') +@click.option('-f', '--folder_id', 'opt_folder_id', required=True, + help='ID of folder on Cortex') +@click.pass_context +def cli(ctx, opt_folder_id): + """ + Test uploading a BytesIO file to Cortex + """ + arr = get_gradation_3d(256, 256, (0, 0, 192), (255, 255, 64), (True, False, False)) + arr = arr.astype(np.uint8) + image = Image.fromarray(arr) + fp = BytesIO() + image.save(fp, format='png') + upload_bytes_to_cortex(opt_folder_id, "test.png", fp, "image/png") + +def get_gradation_2d(start, stop, width, height, is_horizontal): + if is_horizontal: + return np.tile(np.linspace(start, stop, width), (height, 1)) + else: + return np.tile(np.linspace(start, stop, height), (width, 1)).T + +def get_gradation_3d(width, height, start_list, stop_list, is_horizontal_list): + result = np.zeros((height, width, len(start_list)), dtype=np.float) + for i, (start, stop, is_horizontal) in enumerate(zip(start_list, stop_list, is_horizontal_list)): + result[:, :, i] = get_gradation_2d(start, stop, width, height, is_horizontal) + return result |
