Skip to content

Instantly share code, notes, and snippets.

View stichbury's full-sized avatar

Jo Stichbury stichbury

View GitHub Profile
@stichbury
stichbury / cell5.py
Created May 9, 2024 11:22
Dashboard from Vizro-AI calls and using Vizro-AI generated chart code
# Dashboard from Vizro-AI calls and using Vizro-AI generated chart code
from vizro import Vizro
import vizro.models as vm
import vizro.plotly.express as px
from vizro.models.types import capture
import plotly.graph_objects as go
import pandas as pd
@capture('graph')
def compare_versions_custom_chart(data_frame=None):
@stichbury
stichbury / cell4.py
Created May 9, 2024 11:20
Dashboard using Vizro-AI calls only
# Dashboard using Vizro-AI calls only
from vizro import Vizro
import vizro.models as vm
import vizro.plotly.express as px
first_page = vm.Page(
title="Documentation traffic dashboard",
layout=vm.Layout(
grid=[
[0, 2],
@stichbury
stichbury / cell3.py
Created May 9, 2024 11:17
Start to set up the Vizro dashboard
from vizro import Vizro
import vizro.models as vm
import vizro.plotly.express as px
first_page = vm.Page(
title="Documentation traffic dashboard",
layout=vm.Layout(
grid=[
[0, 2],
@stichbury
stichbury / cell2.py
Created May 9, 2024 11:14
Two further calls to Vizro-AI
# Total views of the top performing stable pages
top_performing_pages_fig = vizro_ai.plot(df, "Collate rows of data for Path where Version==stable. Create a horizontal bar chart describing the total Views for the top 5 pages. Add the numbers to each bar. Decrease font size of marks", explain=True)
top_performing_pages_fig.show()
# Top 5 performing pages on stable by date
top_pages_by_date_fig = vizro_ai.plot(df, "Collate rows of data for Path where Version==stable. Create a line graph for the total Views per Date for the top 5 Paths", explain=True)
top_pages_by_date_fig.show()
@stichbury
stichbury / cell1.py
Created May 9, 2024 11:09
Set up Vizro-AI and make a call to plot()
import vizro_ai
from vizro_ai import VizroAI
from dotenv import load_dotenv
load_dotenv()
vizro_ai = VizroAI(model="gpt-4–0613")
compare_versions_fig = vizro_ai.plot(df, "Combine rows of Views for each Date for latest and stable Version. Draw a line graph comparing Views per Date for latest and stable", explain=True)
compare_versions_fig.show()
from kedro.config import OmegaConfigLoader
from kedro.io import DataCatalog
conf_loader = OmegaConfigLoader(".", base_env="", default_run_env="")
conf_catalog = conf_loader["catalog"]
# Create the DataCatalog instance from the configuration
catalog = DataCatalog.from_config(conf_catalog)
# Load the datasets
@stichbury
stichbury / add_kedro_to_a_notebook.ipynb
Created October 3, 2023 16:05
Add Kedro features to a notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stichbury
stichbury / convert_a_notebook_to_kedro.ipynb
Last active October 3, 2023 15:55
Add Kedro to notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def create_pipeline(**kwargs):
return Pipeline(
[
node(
func=split_data,
inputs=["master_table", "parameters"],
outputs=["X_train", "X_test", "y_train", "y_test"],
name="split_data_node",
),
node(
def split_data(data: pd.DataFrame, parameters: Dict) -> Tuple:
"""Splits data into features and targets training and test sets.
Args:
data: Data containing features and target.
parameters: Parameters defined in parameters.yml.
Returns:
Split data.
"""
X = data[parameters["features"]]