File size: 5,657 Bytes
5b68c01
4df9e3a
 
5b68c01
4df9e3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512491e
4df9e3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b68c01
4df9e3a
 
 
 
 
 
 
 
 
 
 
 
 
 
5b68c01
6c15782
 
4df9e3a
 
 
 
6c15782
 
 
4df9e3a
6c15782
4df9e3a
 
 
 
6c15782
 
 
 
 
4df9e3a
 
 
033655d
4df9e3a
 
fe8d156
 
cd7e290
fe8d156
 
cd7e290
4df9e3a
6c15782
4df9e3a
 
 
 
 
 
 
 
 
 
67f3d25
4df9e3a
cd7e290
 
 
48b6f87
cd7e290
 
 
 
 
 
 
 
 
fe8d156
cd7e290
 
 
 
48b6f87
6c15782
 
 
4df9e3a
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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"<style>{style}</style>", 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"<style>{style}</style>", 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()