balthou's picture
add gifs for backend speeds
74f19b4
|
raw
history blame
1.66 kB

Tutorial

Keep separation between "production code" (library / not interactive) & interactivity

  • πŸ’‘ One of the strength of interactive pipe is to avoid adding hundreds of lines of code dedicated to GUI (graphical user interfaces).
  • With interactive pipe, you have the choice to keep this design choice. Each processing block can be defined as a regular function, without even importing the interactive decorator. In a separate file, you'll add sliders.

Several ways to decorate building blocks

1.Decorate afterward πŸ† = Recommended approach

  • βž– Less elegant to read (add_interactivity may be in a different file)
  • βž• The decorated function can't be re-used somewhere else.
  • βž• Possibility to add conditions (debug flag)
def gen_color(frequency=0, isotropy=0.):
    ...


def add_interactivity(debug=True):
    interactive(
        frequency=(80, [1, 100]),
        isotropy=(0.8, [0.1, 1.]) if debug else 0.8
    )(gen_color)

2.Decorate using @

@interactive(
    frequency=(80, [1, 100]),
    isotropy=(0.8, [0.1, 1.])
)
def gen_color(frequency=0, isotropy=0.):
    ...
  • βž• Easy to read
  • βž– The decorated function can't be re-used somewhere else.
  • βž– No possibility to add condition to hide/show slider. To hide the slider, you need to comment!

3. Shorter code using @

@interactive()
def gen_color(
    frequency=(80, [1, 100]),
    isotropy=(0.8, [0.1, 1.])
):
  • βž• Shortest code
  • βž– The decorated function can't be re-used somewhere else

Backend choice

πŸš€ Qt 🐒 Gradio
QT Gradio