Not logged in!

List

The List object allows you to receive inputs via a list
Introduction

The List class allows you to provide a single select list or multi-select list.

Contents

List.SelectOne

List.SelectOne allows you to output a list which a user can select an item from.

Example Applications:

  • Input for a conditional GAN

Example Usage
1import feather as ftr
2from my_model import my_conditional_gan
3
4def init():
5    #################### CONSTRUCTOR ####################
6    list_options = ftr.List.SelectOne(items=["cat", "dog", "bird"], style="dropdown",
7                                      title="Select an item to generate an image on!")
8    #####################################################
9    return list_options
10    
11def run_gan(list_options):
12    #################### ACCESSOR ####################
13    selected = list_options.get_selected_with_index() # equivalent to 'list_options.get(return_index=True)'
14    ##################################################
15    # selected = ("dog", 1)
16    
17    generated_image = my_conditional_gan(selected) # np.ndarray
18    return ftr.Image.View(images=[generated_image])
19    
20if __name__ == "__main__":
21    bundle = ftr.bundle(code_files=[__file__, "my_model.py"], model_files=["outputs/model.ckpt"])
22    ftr.build(name="Conditional GAN model", init=init, steps=[run_gan], file_bundle=bundle)

Constructor:
  • items: ListType[str] - a list of for an end user to select from
  • style: Literal["radio", "dropdown"] = "radio" - whether to display the items as radio buttons or dropdowns. Defaults to radio buttons
  • title: Optional[str] = None - a title semantically attached to the component
  • description: Optional[str] = None - a description semantically attached to the component

Accessors:
  • get_selected() -> str - returns the selected item
  • get_selected_with_index() -> Tuple[str, int] - returns a tuple as (<item>, <index>). Index indicates which item index the string value in the itemslist in the constructor is
  • get(return_index=False) - see below
get() (usage of .get() is not recommended)
get(return_index=False):
    if return_index:
        return get_selected_with_index()
    return get_selected()

Component Playground:
Arg NameValue
items
style
title
description
ftr.List.SelectOne(
    items=["cat", "dog", "bird"], 
    style="radio",
    title="Select an object", 
    description="Select an object to generate an image on it")
List.SelectMulti

List.SelectMulti allows you to output a list which a user can select multiple items from.

Example Applications:

  • Input to a conditional GAN with styling options

Example Usage
1import feather from ftr
2from my_model import my_conditional_gan
3
4def init():
5    #################### CONSTRUCTOR ####################
6    list_options = ftr.List.SelectMulti(items=[("cartoonise", True), ("psychedelic", True), ("picasso style", False)],
7                                      title="Select items to generate an image in that style!")
8    #####################################################
9    return list_options
10    
11def run_gan(list_options):
12    #################### ACCESSOR ####################
13    selected = list_options.get_selected() # ["psychedelic", "picasso style"] # equivalent to 'list_options.get()'
14    # list_options.get_all() --> [("cartoonise", False), ("psychedelic", True), ("picasso style", True)]
15    ##################################################
16    
17    generated_image = my_conditional_gan(selected) # np.ndarray
18    return ftr.Image.View(images=[generated_image])
19
20if __name__ == "__main__":
21    bundle = ftr.bundle(code_files=[__file__, "my_model.py"], model_files=["outputs/model.ckpt"])
22    ftr.build(name="Conditional GAN model", init=init, steps=[run_gan], file_bundle=bundle)

Constructor:
  • items: Union[ListType[str], ListType[Tuple[str, bool]]] - a list of strings, or a tuple of strings, containing items for an end user to select from. If a list of strings, checkbox values default to false. List of tuples are in the format (<item>, <boolean>) where you can specify which items are selected by default.
  • title: Optional[str] = None - a title semantically attached to the component
  • description: Optional[str] = None - a description semantically attached to the component

Accessors:
  • get_selected() -> ListType[str] - returns a list of the selected items
  • get_all -> Tuple[str, int] - a list of tuples, in format (<item>, <boolean>), which contains the item value, and a boolean to indicate whether that item was selected or not.
  • get(return_all=False) - see below
get() (usage of .get() is not recommended)
get(return_all=False):
    if return_all:
        return get_all()
    return get_selected()

Component Playground:
Arg NameValue
items
title
description
ftr.List.SelectMulti(
    items=[("cartoonise", True), ("psychedelic", False), ("picasso style", True)], 
    title="Select objects", 
    description="Select objects you want a caption generated/conditioned on")