-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separation of signals dataframes and detailed analysis in separate tabs
- Loading branch information
Showing
7 changed files
with
168 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# See AUTHORS.txt | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# This file is part of BERTrend. | ||
|
||
import uuid | ||
from typing import Any | ||
|
||
import pandas as pd | ||
import streamlit as st | ||
|
||
from bertrend.demos.demos_utils.icons import WARNING_ICON | ||
from bertrend_apps.prospective_demo import NOISE, WEAK_SIGNALS, STRONG_SIGNALS | ||
from bertrend_apps.prospective_demo.models_info import get_models_info | ||
|
||
COLS_RATIO_ID_TS = [2 / 7, 5 / 7] | ||
|
||
|
||
@st.cache_data | ||
def get_df_topics(model_interpretation_path=None) -> dict[str, pd.DataFrame]: | ||
dfs_topics = {} | ||
for df_id in [NOISE, WEAK_SIGNALS, STRONG_SIGNALS]: | ||
df_path = model_interpretation_path / f"{df_id}.parquet" | ||
dfs_topics[df_id] = ( | ||
pd.read_parquet(df_path) if df_path.exists() else pd.DataFrame() | ||
) | ||
return dfs_topics | ||
|
||
|
||
def update_key(key: str, new_value: Any): | ||
st.session_state[key] = new_value | ||
|
||
|
||
def choose_id_and_ts(): | ||
col1, col2 = st.columns(COLS_RATIO_ID_TS) | ||
with col1: | ||
options = sorted(st.session_state.user_feeds.keys()) | ||
if "model_id" not in st.session_state: | ||
st.session_state.model_id = options[0] | ||
model_id_key = uuid.uuid4() | ||
model_id = st.selectbox( | ||
"Sélection de la veille", | ||
options=options, | ||
index=options.index(st.session_state.model_id), | ||
key=model_id_key, # to avoid pb of unicity if displayed on several places | ||
on_change=lambda: update_key("model_id", st.session_state[model_id_key]), | ||
) | ||
with col2: | ||
list_models = get_models_info(model_id) | ||
if not list_models: | ||
st.warning(f"{WARNING_ICON} Pas de modèle disponible") | ||
st.stop() | ||
elif len(list_models) < 2: | ||
st.warning( | ||
f"{WARNING_ICON} 2 modèles minimum pour analyser les tendances !" | ||
) | ||
st.stop() | ||
if "reference_ts" not in st.session_state: | ||
st.session_state.reference_ts = list_models[-1] | ||
ts_key = uuid.uuid4() | ||
reference_ts = st.select_slider( | ||
"Date d'analyse", | ||
options=list_models, | ||
value=st.session_state.reference_ts, | ||
format_func=lambda ts: ts.strftime("%d/%m/%Y"), | ||
help="Sélection de la date d'analyse parmi celles disponibles", | ||
key=ts_key, # to avoid pb of unicity if displayed on several places | ||
on_change=lambda: update_key("reference_ts", st.session_state[ts_key]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# See AUTHORS.txt | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# This file is part of BERTrend. | ||
|
||
import streamlit as st | ||
|
||
from bertrend.demos.weak_signals.visualizations_utils import ( | ||
display_signal_categories_df, | ||
) | ||
from bertrend_apps.prospective_demo import ( | ||
LLM_TOPIC_DESCRIPTION_COLUMN, | ||
NOISE, | ||
WEAK_SIGNALS, | ||
STRONG_SIGNALS, | ||
get_model_interpretation_path, | ||
) | ||
from bertrend_apps.prospective_demo.dashboard_common import ( | ||
choose_id_and_ts, | ||
get_df_topics, | ||
) | ||
|
||
|
||
def signal_analysis(): | ||
st.write( | ||
"Ici mettre seulement les tableaux weak / strong + les liens vers les articles" | ||
) | ||
# ID and timestamp selection | ||
choose_id_and_ts() | ||
model_id = st.session_state.model_id | ||
reference_ts = st.session_state.reference_ts | ||
|
||
model_interpretation_path = get_model_interpretation_path( | ||
user_name=st.session_state.username, | ||
model_id=model_id, | ||
reference_ts=reference_ts, | ||
) | ||
|
||
# Display dataframes for weak_signals, strong, etc | ||
# Display data frames | ||
columns = [ | ||
"Topic", | ||
LLM_TOPIC_DESCRIPTION_COLUMN, | ||
"Representation", | ||
"Latest_Popularity", | ||
"Docs_Count", | ||
"Paragraphs_Count", | ||
"Latest_Timestamp", | ||
"Documents", | ||
"Sources", | ||
"Source_Diversity", | ||
] | ||
|
||
dfs_topics = get_df_topics(model_interpretation_path) | ||
display_signal_categories_df( | ||
dfs_topics[NOISE], | ||
dfs_topics[WEAK_SIGNALS], | ||
dfs_topics[STRONG_SIGNALS], | ||
reference_ts, | ||
columns=columns, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.