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

✨ wizard: anomalist #3598

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions apps/wizard/app_pages/anomalist/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ def llm_ask(df: pd.DataFrame):
)


@st.fragment()
def download_anomalies(df: pd.DataFrame):
csv_data = convert_df_to_csv(df)
st.download_button(
"Export data (CSV)",
data=csv_data,
file_name="data.csv",
mime="text/csv",
icon=":material/download:",
help="Download the anomalies as a CSV file. Selected filters apply!",
)


@st.dialog("AI summary of anomalies", width="large")
def llm_dialog(df: pd.DataFrame):
"""Ask LLM for summary of the anomalies."""
Expand Down Expand Up @@ -360,6 +373,13 @@ def _sort_df(df: pd.DataFrame, sort_strategy: Union[str, List[str]]) -> Tuple[pd
return df, columns_sort


# Function to convert DataFrame to CSV
@st.cache_data
def convert_df_to_csv(df):
df["indicator_uri"] = df["indicator_id"].apply(lambda x: st.session_state.anomalist_indicators.get(x))
return df.to_csv(index=False).encode("utf-8")


# Functions to show the anomalies
@st.fragment
def show_anomaly_compact(index, df):
Expand Down Expand Up @@ -425,6 +445,8 @@ def show_anomaly_compact(index, df):
else:
config = bake_chart_config(variable_id=indicator_id, selected_entities=entities)
config["hideAnnotationFieldsInTitle"]["time"] = True
config["hideFacetControl"] = False

# Actually plot
grapher_chart(chart_config=config, owid_env=OWID_ENV)

Expand Down Expand Up @@ -769,8 +791,11 @@ def _score_table(df: pd.DataFrame) -> pd.DataFrame:

# Show anomalies with time and version changes
if not df.empty:
# LLM summary option
llm_ask(df)
# Top option buttons
with st_horizontal():
# LLM summary option
llm_ask(df)
download_anomalies(df)

# st.dataframe(df_change)
groups = df.groupby(["indicator_id", "type"], sort=False, observed=True)
Expand Down
Loading