Source code for diva.gui.service_streamlit.sidebar

# Copyright 2024 Mews
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

import streamlit as st

from diva.logging.logger import Process
from diva import tools

[docs] def app_sidebar(tab_id): """ Configures the sidebar of the DestinE Chatbot application based on the selected tab. The sidebar is populated with various widgets, such as language selection and a button to clear the conversation, depending on the tab currently active in the application. It also includes static content like the last update time and a logo. Parameters: ---------- tab_id : int Identifier for the current tab. Different widgets are displayed depending on the tab selected. If `tab_id` is 1, language selection and a conversation clearing button are provided. Returns: ------- dict or None A dictionary containing the selected sidebar options (`clear_conv` and `langage`) if `tab_id` is 1, or `None` if no options are provided for the selected tab. """ options = None if tab_id == 1: dev_mode = st.sidebar.toggle("Activate developper mode") language = st.sidebar.selectbox("Select the language ", ['English', 'French', 'Spanish', 'German', 'Italian', 'Dutch']) clear_conv = st.sidebar.button( "Clear the conversation", use_container_width=True) options = {"dev_mode": dev_mode, "clear_conv": clear_conv, "langage": language, } if tab_id == 2: options = None if "process_logging" not in st.session_state: st.session_state.process_logging = Process(text_language='html') if "history_logging" not in st.session_state: st.session_state.history_logging = st.session_state.process_logging.doc() if "energy_consumption" not in st.session_state: st.session_state.energy_consumption = {} with st.sidebar.expander("**Python function console**"): st.session_state.log_container = st.empty() if st.session_state.history_logging != '': st.session_state.log_container.markdown( f""" <div style="height: 300px; overflow-y: scroll; padding: 10px;"> {st.session_state.history_logging} </div> """, unsafe_allow_html=True) st.sidebar.divider() st.sidebar.write("**Energy consumption**") st.session_state.consumption_container = st.sidebar.container(border=True) nrg = st.session_state.energy_consumption tools.show_energy_consumption(nrg) st.sidebar.divider() st.sidebar.write("**Last update of DIVA**: " + ':green[2025-01-21]') st.sidebar.divider() st.sidebar.write("*Made by*") st.sidebar.image("../images/mews_partners.png", width=100) return options