Guidelines
To create an app using NeuralAutomata, we need to follow the hierarchy of app -> page -> states
App
In Python implementation of NeuralAutomata, the app is implemented by AutomataGradio
class, since the UI is achieved by gradio. For example:
the GradioRender.render
function will launch the gradio app.
Page
States
It is crucial to understand how to arrange the states inside a page to make it work properly. As a NestedState
, the execution of AutomataPage
would start from the state defined by start_at
and perform state transfer according to the next_state
property of each state, and stop when the next_state
of a state is None
or the current state name equals the end_at
attribute. When the state machine is halted, we can use event listeners to jump to another state and resume the automata. A common case is that when we want the user to input some information (e.g., via Textbox
, Dropdown
, etc):
in the example above, the automata will halt after the execution of first_state, and when the user click the confirm_btn
it will jump to input_state
and resume the automata.
It is a common usage that a page will stop at the very beginning to wait for user inputs. We then introduce a new attribute for NestedState
called use_idle_state
. When use_idle_state=True
, an idle state (the next_state
of which is None) is created and the nested state will start from it and then halt to wait for user inputs.
Context
Other tricks
Setting the Next State Dynamically
Sometimes we need to dynamically determine the next state name. This can be achieved by modifying the value of NEXT_STATE_NAME
If NEXT_STATE_NAME
is set properly, the get_next_state
method of NestedState
will return that instead of self.next_state
Last updated