figoyouwei / taipy_success

This is a sample code that tests the deployment on heroku
2 stars 2 forks source link

List content display and process rotate #5

Closed figoyouwei closed 3 months ago

figoyouwei commented 3 months ago

I've committed apps/enterpriser https://github.com/figoyouwei/taipy_success/tree/main/apps/enterpriser

The GUI is simple, I need to display some List content, here facts variable, returned by the llm using pydantic model class Summary(BaseModel): summary: str = Field(description="Summary") facts: List[str] = Field(description="Facts")

  1. how to efficiently do that
  2. as waiting for the response from llm, is there a rotating element to hold onto when it is processing.
FlorianJacta commented 3 months ago

You can use asynchronous callbacks. These callbacks allow you to not block your UI when your application performs a heavy task.

Here is some documentation for it: https://docs.taipy.io/en/develop/tutorials/visuals/4_long_callbacks/

This allows you to perform a heavy task and regularly update your app. You can use a progress visual element to give feedback to your end users or notifications.

I don't know if this answers your question.

figoyouwei commented 3 months ago

let's do it one by one, first the progress, could you add some code in the "on_filter" function, so that it works? https://github.com/figoyouwei/taipy_success/blob/main/apps/enterpriser/main.py

FlorianJacta commented 3 months ago

Add a progress visual element where you cant inside your page:

render_progress = False
progress_value = None
...
tgb.progress("{progress_value }", render="{render_progress}")
...

When you want this progress to appear, you can just put render_progress to True. So, in your on_filter:

def on_filter(state):
    ...
    state.render_progress = True

You might need asynchronous callbacks, but we'll see later.

figoyouwei commented 3 months ago

how come it returns this error... AttributeError: module 'taipy.gui.builder' has no attribute 'progress' Please check the latest commit.

FlorianJacta commented 3 months ago

This is inside the 4.0 release as well as the chat visual element.

Having a progress visual element is not compulsory. It may be better to stay on 3.1 for now

figoyouwei commented 3 months ago

ok, forget the progress element for now, is there an easy to visualize listed items?

FlorianJacta commented 3 months ago

How would you want them to visualize them? You should just create a function that makes it a string or int or anything handled by Taipy

figoyouwei commented 3 months ago

For the first step: just loop over a List and render the content with tgb.text would be ok, code would look like: facts = ['apple', 'banana', 'cherry'] for index, fact in enumerate(facts): tgb.text(f"{index}: {fact}", mode="md")

Obviously, this code doesn't work. So how to do it?

FlorianJacta commented 3 months ago

Ok, I see. To achieve that, you should create a partial that can be dynamically updated.

https://docs.taipy.io/en/develop/manuals/userman/gui/pages/partial/

Replace the building of the partial in the code you find above what you just sent me:

def build_your_partial(facts):
    with tgb.Page() as new_partial:
        for index, fact in enumerate(facts):
            tgb.text(f"{index}: {fact}", mode="md")
    return new_partial
figoyouwei commented 3 months ago

I see, partial is the way to make the GUI code modularized, is that correct? My little example works now, thanks.

FlorianJacta commented 3 months ago

Yes, it is a way to make it modularized, but it is more used to create a dynamic part for your page.