import streamlit as st # type: ignore
import os.path
from collections import OrderedDict
from streamlit_option_menu import option_menu # type: ignore
# Define TITLE, TEAM_MEMBERS and PROMOTION values, in config.py.
import config
from tabs.custom_vectorizer import custom_tokenizer, custom_preprocessor
import os
from translate_app import tr
# Initialize a session state variable that tracks the sidebar state (either 'expanded' or 'collapsed').
if 'sidebar_state' not in st.session_state:
st.session_state.sidebar_state = 'expanded'
else:
st.session_state.sidebar_state = 'auto'
st.set_page_config (
page_title=config.TITLE,
page_icon= "assets/faviconV2.png",
layout="wide",
initial_sidebar_state=st.session_state.sidebar_state
)
# Si l'application tourne localement, session_state.Cloud == 0
# Si elle tourne sur le Cloud de Hugging Face, ==1
st.session_state.Cloud = 1
# En fonction de la valeur de varible précédente, le data path est différent
if st.session_state.Cloud == 0:
st.session_state.DataPath = "../data"
st.session_state.ImagePath = "../images"
st.session_state.reCalcule = False
else:
st.session_state.DataPath = "data"
st.session_state.ImagePath = "images"
st.session_state.reCalcule = False
# Define the root folders depending on local/cloud run
# thisfile = os.path.abspath(__file__)
# if ('/' in thisfile):
# os.chdir(os.path.dirname(thisfile))
# Nécessaire pour la version windows 11
if st.session_state.Cloud == 0:
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
# Tabs in the ./tabs folder, imported here.
from tabs import intro, sentence_similarity_tab, speech2text_tab, chatbot_tab
with open("style.css", "r") as f:
style = f.read()
st.markdown(f"", unsafe_allow_html=True)
# Add tab in this ordered dict by
# passing the name in the sidebar as key and the imported tab
# as value as follow :
TABS = OrderedDict(
[
(tr(intro.sidebar_name), intro),
(tr(chatbot_tab.sidebar_name), chatbot_tab),
(tr(sentence_similarity_tab.sidebar_name), sentence_similarity_tab),
# (tr(speech2text_tab.sidebar_name), speech2text_tab),
]
)
# Utilisation du module deep_translator
lang_tgt = ['fr', 'en','de','es', 'it', 'nl']
label_lang = ['Français','English','Deutsch','Español','Italiano','Nederlands']
label_lang_en = ['French', 'English', 'German', 'Spanish', 'Italian', 'Dutch']
# @st.cache_data
def find_lang_label(lang_sel):
global lang_tgt, label_lang
return label_lang[lang_tgt.index(lang_sel)]
# @st.cache_data
def find_lang_label_en(lang_sel):
global lang_tgt, label_lang_en
return label_lang_en[lang_tgt.index(lang_sel)]
def run():
st.sidebar.image(
"assets/value_props_logo.png",
width=270,
)
with st.sidebar.expander(":red[**"+tr("Développez moi")+"**]"):
# st.markdown(f"", unsafe_allow_html=True)
st.markdown(tr("""
:red[Cette application vous permet de tester les futures fonctionnalités de la plateforme Value Props, et plus particulièrement le «Sales Coaching».
Amusez vous bien !]
"""))
with st.sidebar:
tab_name = option_menu(None, list(TABS.keys()),
# icons=['house', 'bi-binoculars', 'bi bi-graph-up', 'bi-chat-right-text','bi-book', 'bi-body-text'], menu_icon="cast", default_index=0,
icons=['house', 'binoculars', 'graph-up', 'search','book', 'chat-right-text','controller'], menu_icon="cast", default_index=0,
styles={"container": {"padding": "0!important","background-color": "#10b8dd", "border-radius": "0!important"},
"nav-link": {"font-size": "1rem", "text-align": "left", "margin":"0em", "padding": "0em",
"padding-left": "0.2em", "--hover-color": "#eee", "font-weight": "400",
"font-family": "Source Sans Pro, sans-serif"}
})
# tab_name = st.sidebar.radio("", list(TABS.keys()), 0)
st.sidebar.markdown("---")
st.sidebar.markdown(f"## {tr(config.PROMOTION)}")
st.sidebar.markdown("### "+tr("Auteur:"))
for member in config.TEAM_MEMBERS:
st.sidebar.markdown(member.sidebar_markdown(), unsafe_allow_html=True)
with st.sidebar:
st.write("")
llm_choice = st.selectbox(tr("Modèle :"),["Mistral large","OpenAI 3.5","OpenAI 4o"], label_visibility="visible")
if (llm_choice == "OpenAI 3.5") : st.session_state.model = "gpt-3.5-turbo"
elif (llm_choice == "OpenAI 4o") : st.session_state.model = "gpt-4o"
else: st.session_state.model = "mistral-large-latest"
if (llm_choice in ["OpenAI 3.5","OpenAI 4o"]) and ('OPENAI_API_KEY' not in st.session_state):
# Set OpenAI API key
st.sidebar.subheader("OpenAI API Key")
openai_api_key = st.sidebar.text_input(tr("Saisissez votre Clé API OpenAI:"), type='password')
if openai_api_key:
os.environ['OPENAI_API_KEY'] = openai_api_key
st.session_state['OPENAI_API_KEY'] = openai_api_key
st.sidebar.success("OpenAI API Key set successfully.")
with st.sidebar:
l = st.selectbox("langue:",lang_tgt, format_func = find_lang_label, key="Language", label_visibility="hidden")
st.session_state.language_label = find_lang_label_en(l)
tab = TABS[tab_name]
tab.run()
if __name__ == "__main__":
run()