Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Dashboard generator #522

Merged
merged 142 commits into from
Aug 2, 2024
Merged

[POC] Dashboard generator #522

merged 142 commits into from
Aug 2, 2024

Conversation

lingyielia
Copy link
Contributor

@lingyielia lingyielia commented Jun 12, 2024

Description

Run

res = vizro_ai.dashboard([df, df_stocks], user_request)
res

or run

hatch run example-create-dashboard

Remaining TODOs:

Screenshot

Notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

    • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.
    • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorized to submit this contribution on behalf of the original creator(s) or their licensees.
    • I certify that the use of this contribution as authorized by the Apache 2.0 license does not violate the intellectual property rights of anyone else.
    • I have not referenced individuals, products or companies in any commits, directly or indirectly.
    • I have not added data or restricted code in any commits, directly or indirectly.

@lingyielia lingyielia temporarily deployed to vizro_ai_secrets June 12, 2024 04:47 — with GitHub Actions Inactive
@lingyielia lingyielia temporarily deployed to circleci_secrets June 12, 2024 04:47 — with GitHub Actions Inactive
@lingyielia lingyielia temporarily deployed to vizro_ai_secrets June 12, 2024 04:47 — with GitHub Actions Inactive
@lingyielia lingyielia temporarily deployed to vizro_ai_secrets June 12, 2024 04:47 — with GitHub Actions Inactive
@lingyielia lingyielia temporarily deployed to vizro_ai_secrets June 12, 2024 04:47 — with GitHub Actions Inactive
@maxschulz-COL
Copy link
Contributor

Nitpick: the output of the progress bar get overwritten to produce:

Generate dashboard plan --> in progress omplex requirements are given): 50%

Maybe we can avoid that?

Copy link
Contributor

@maxschulz-COL maxschulz-COL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how far I got until now - looking really great!

Copy link
Contributor

@maxschulz-COL maxschulz-COL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ 🚀 ❤️ Incredible work - really love is !!!

I am almost through, basically just the Layout to go - but approving already now as I think this is in very good shape already!! Well done, you should be very proud!

vizro-ai/src/vizro_ai/dashboard/_response_models/types.py Outdated Show resolved Hide resolved
component_id: str = Field(
pattern=r"^[a-z]+(_[a-z]+)?$", description="Small snake case description of this component."
)
df_name: str = Field(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not have a validator that verifies this DF is even present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Although this means we would need to create ComponentPlan at run time too, so the validator can access the "all_df_metadata". Something like this:

@root_validator(allow_reuse=True)
    def _check_df_name(cls, values):
        df_name = values.get("df_name")
        component_id = values.get("component_id")
        component_description = values.get("component_description")
        available_df_names = all_df_metadata.get_df_names()
        if df_name not in available_df_names:
            logger.warning(
                f"""
[FALLBACK] Failed to build `Component`: {component_id}.
Reason: Dataframe `{df_name}` not found in metadata df names `{available_df_names}`.
Relevant prompt: {component_description}
"""
            )
            return {"component_type": "Card", "component_id": component_id, "component_description": f"Failed to build component: {component_id}", "df_name": "N/A"}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave as is for now, as it would be a slightly big refactor. Let's discuss further before taking actions

try:
page = vm.Page(title=title, components=components, controls=controls, layout=layout)
except Exception as e:
if any("Number of page and grid components need to be the same" in error["msg"] for error in e.errors()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not catch this earlier, when the layout is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I created the ticket for next sprint to revisit this. Ideally we should return no layout if failed.

vizro-ai/src/vizro_ai/dashboard/_pydantic_output.py Outdated Show resolved Hide resolved
vizro-ai/src/vizro_ai/dashboard/utils.py Outdated Show resolved Hide resolved
vizro-ai/src/vizro_ai/dashboard/utils.py Outdated Show resolved Hide resolved
vizro-ai/src/vizro_ai/py.typed Outdated Show resolved Hide resolved
Copy link
Contributor

@maxschulz-COL maxschulz-COL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳 Awesome, took a look at the last bits - I think I cannot find anything for the moment any more - looking forward to the merge!!

return grid


class LayoutPlan(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not enhance this model with validators? Basically we can check if the number of components etc is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, replied in an earlier thread. Will revisit in next sprint 🙌

vizro-ai/src/vizro_ai/dashboard/_response_models/layout.py Outdated Show resolved Hide resolved
vizro-ai/src/vizro_ai/dashboard/_response_models/layout.py Outdated Show resolved Hide resolved
vizro-ai/src/vizro_ai/dashboard/_response_models/layout.py Outdated Show resolved Hide resolved
raise ValidationError(f"Component ids must be unique. Duplicated component ids: {duplicates}")
return values

def __init__(self, **data):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this custom __init__?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make those 3 private attributes visible, otherwise got attribute error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm let's revisit this

vizro-ai/src/vizro_ai/dashboard/_response_models/layout.py Outdated Show resolved Hide resolved
@lingyielia lingyielia merged commit 4187e95 into main Aug 2, 2024
37 checks passed
@lingyielia lingyielia deleted the dev/dashboard_generator branch August 2, 2024 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Vizro-AI 🤖 Issue/PR that addresses Vizro-AI package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants