Demosthene-OR commited on
Commit
4311668
·
1 Parent(s): a36d93b
.gitattributes CHANGED
@@ -1,4 +1,4 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
4
  *.bz2 filter=lfs diff=lfs merge=lfs -text
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
1
+ preprocess_txt_split*.7z filter=lfs diff=lfs merge=lfs -text
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
4
  *.bz2 filter=lfs diff=lfs merge=lfs -text
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ sentences.csv filter=lfs diff=lfs merge=lfs -text
37
+ preprocess_df_count_word* filter=lfs diff=lfs merge=lfs -text
38
+ preprocess_txt_split* filter=lfs diff=lfs merge=lfs -text
39
+
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # DotEnv configuration
2
+ .env
3
+ #
4
+ *.pyc
5
+
6
+ /tabs/__pycache__
7
+ /__pycache__
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
- title: ChatGPT Playground
3
- emoji: 📈
4
- colorFrom: purple
5
- colorTo: purple
6
  sdk: streamlit
7
- sdk_version: 1.41.1
8
  app_file: app.py
9
  pinned: false
10
- short_description: .. to see the token generation (Model used=davinci-002)
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Playgrount ChatGPT
3
+ emoji: 🏆
4
+ colorFrom: red
5
+ colorTo: red
6
  sdk: streamlit
7
+ sdk_version: 1.38.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st # type: ignore
2
+ import os.path
3
+ from collections import OrderedDict
4
+ from streamlit_option_menu import option_menu # type: ignore
5
+ # Define TITLE, TEAM_MEMBERS and PROMOTION values, in config.py.
6
+ import config
7
+ import os
8
+ import openai
9
+ from dotenv import load_dotenv
10
+ from translate_app import tr
11
+
12
+ # Initialize a session state variable that tracks the sidebar state (either 'expanded' or 'collapsed').
13
+ if 'sidebar_state' not in st.session_state:
14
+ st.session_state.sidebar_state = 'expanded'
15
+ else:
16
+ st.session_state.sidebar_state = 'auto'
17
+
18
+ st.set_page_config (
19
+ page_title=config.TITLE,
20
+ page_icon= "assets/favicon.png",
21
+ initial_sidebar_state=st.session_state.sidebar_state
22
+ )
23
+
24
+ # Si l'application tourne localement, session_state.Cloud == 0
25
+ # Si elle tourne sur le Cloud de Hugging Face, ==1
26
+ st.session_state.Cloud = 0
27
+ st.session_state.DataPath = "data"
28
+ st.session_state.ImagePath = "images"
29
+ st.session_state.reCalcule = False
30
+
31
+ # Define the root folders depending on local/cloud run
32
+ # thisfile = os.path.abspath(__file__)
33
+ # if ('/' in thisfile):
34
+ # os.chdir(os.path.dirname(thisfile))
35
+
36
+ # Nécessaire pour la version windows 11
37
+ if st.session_state.Cloud == 0:
38
+ os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
39
+
40
+
41
+ # Tabs in the ./tabs folder, imported here.
42
+ from tabs import playground
43
+
44
+
45
+ with open("style.css", "r") as f:
46
+ style = f.read()
47
+
48
+ st.markdown(f"<style>{style}</style>", unsafe_allow_html=True)
49
+
50
+
51
+ # Add tab in this ordered dict by
52
+ # passing the name in the sidebar as key and the imported tab
53
+ # as value as follow :
54
+ TABS = OrderedDict(
55
+ [
56
+ (tr(playground.sidebar_name), playground),
57
+ # (tr(sentence_similarity_tab.sidebar_name), sentence_similarity_tab),
58
+ # (tr(speech2text_tab.sidebar_name), speech2text_tab),
59
+ # (tr(chatbot_tab.sidebar_name), chatbot_tab),
60
+ ]
61
+ )
62
+
63
+ # Utilisation du module deep_translator
64
+ lang_tgt = ['fr', 'en', 'af', 'ak', 'sq', 'de', 'am', 'en', 'ar', 'hy', 'as', 'ay', 'az', 'bm', 'eu', 'bn', 'bho', 'be', 'my', 'bs', 'bg', 'ca', 'ceb', 'ny', 'zh-CN', 'zh-TW', 'si', 'ko', 'co', 'ht', 'hr', 'da', 'doi', 'gd', 'es', 'eo', 'et', 'ee', 'fi', 'fr', 'fy', 'gl', 'cy', 'lg', 'ka', 'el', 'gn', 'gu', 'ha', 'haw', 'iw', 'hi', 'hmn', 'hu', 'ig', 'ilo', 'id', 'ga', 'is', 'it', 'ja', 'jw', 'kn', 'kk', 'km', 'rw', 'ky', 'gom', 'kri', 'ku', 'ckb', 'lo', 'la', 'lv', 'ln', 'lt', 'lb', 'mk', 'mai', 'ms', 'ml', 'dv', 'mg', 'mt', 'mi', 'mr', 'mni-Mtei', 'lus', 'mn', 'nl', 'ne', 'no','or', 'om', 'ug', 'ur', 'uz', 'ps', 'pa', 'fa', 'pl', 'pt', 'qu', 'ro', 'ru', 'sm', 'sa', 'nso', 'sr', 'sn', 'sd', 'sk', 'sl', 'so', 'st', 'su', 'sv', 'sw', 'tg', 'tl', 'ta', 'tt', 'cs', 'te', 'th', 'ti', 'ts', 'tr', 'tk', 'uk', 'vi', 'xh', 'yi', 'yo', 'zu']
65
+ label_lang = ['Français', 'Anglais / English','Afrikaans','Akan','Albanais','Allemand / Deutsch','Amharique','Anglais','Arabe','Arménien','Assamais','Aymara','Azéri','Bambara','Basque','Bengali','Bhojpuri','Biélorusse','Birman','Bosnien','Bulgare','Catalan','Cebuano','Chichewa','Chinois (simplifié)','Chinois (traditionnel)','Cingalais','Coréen','Corse','Créole haïtien','Croate','Danois','Dogri','Écossais','Espagnol / Español','Espéranto','Estonien','Ewe','Finnois','Français','Frisonoccidental','Galicien','Gallois','Ganda','Géorgien','Grec moderne','Guarani','Gujarati','Haoussa','Hawaïen','Hébreu','Hindi','Hmong','Hongrois','Igbo','Ilocano','Indonésien','Irlandais','Islandais','Italien / Italiano','Japonais','Javanais','Kannada','Kazakh','Khmer','Kinyarwanda','Kirghiz','Konkani','Krio','Kurde','Kurde (Sorani)','Lao','Latin','Letton','Lingala','Lituanien','Luxembourgeois','Macédonien','Maithili','Malais','Malayalam','Maldivien','Malgache','Maltais','Maori de Nouvelle-Zélande','Marathi','Meiteilon (Manipuri)','Mizo','Mongol','Néerlandais / Nederlands','Népalais','Norvégien','Oriya','Oromo','Ouïghour','Ourdou','Ouzbek','Pachto','Pendjabi','Persan','Polonais','Portugais','Quechua','Roumain','Russe','Samoan','Sanskrit','Sepedi','Serbe','Shona','Sindhi','Slovaque','Slovène','Somali','Sotho du Sud','Soundanais','Suédois','Swahili','Tadjik','Tagalog','Tamoul','Tatar','Tchèque','Télougou','Thaï','Tigrigna','Tsonga','Turc','Turkmène','Ukrainien','Vietnamien','Xhosa','Yiddish','Yoruba','Zulu']
66
+
67
+ @st.cache_data
68
+ def find_lang_label(lang_sel):
69
+ global lang_tgt, label_lang
70
+ return label_lang[lang_tgt.index(lang_sel)]
71
+
72
+ def run():
73
+
74
+ st.sidebar.image(
75
+ "assets/Logo_TPA.png",
76
+ width=270,
77
+ )
78
+ with st.sidebar:
79
+ tab_name = option_menu(None, list(TABS.keys()),
80
+ # icons=['house', 'bi-binoculars', 'bi bi-graph-up', 'bi-chat-right-text','bi-book', 'bi-body-text'], menu_icon="cast", default_index=0,
81
+ icons=['house', 'binoculars', 'graph-up', 'search','book', 'chat-right-text','controller'], menu_icon="cast", default_index=0,
82
+ styles={"container": {"padding": "0!important","background-color": "#10b8dd", "border-radius": "0!important"},
83
+ "nav-link": {"font-size": "1rem", "text-align": "left", "margin":"0em", "padding": "0em",
84
+ "padding-left": "0.2em", "--hover-color": "#eee", "font-weight": "400",
85
+ "font-family": "Source Sans Pro, sans-serif"}
86
+ })
87
+ st.sidebar.markdown("---")
88
+ st.sidebar.markdown(f"## {tr(config.PROMOTION)}")
89
+
90
+ st.sidebar.markdown("### "+tr("Auteur:"), unsafe_allow_html=True)
91
+ for member in config.TEAM_MEMBERS:
92
+ st.sidebar.markdown(member.sidebar_markdown(), unsafe_allow_html=True)
93
+
94
+ with st.sidebar:
95
+ st.write("")
96
+ if ('OPENAI_API_KEY' not in st.session_state):
97
+ # Set OpenAI API key
98
+ st.sidebar.subheader("OpenAI API Key")
99
+ openai_api_key = st.sidebar.text_input(tr("Saisissez votre Clé API OpenAI:"), type='password')
100
+ if openai_api_key:
101
+ os.environ['OPENAI_API_KEY'] = openai_api_key
102
+ st.session_state['OPENAI_API_KEY'] = openai_api_key
103
+ st.sidebar.success("OpenAI API Key set successfully.")
104
+ with st.sidebar:
105
+ st.selectbox("langue:",lang_tgt, format_func = find_lang_label, key="Language", label_visibility="hidden")
106
+
107
+ tab = TABS[tab_name]
108
+ tab.run()
109
+
110
+ if __name__ == "__main__":
111
+ run()
assets/Logo_TPA.png ADDED
assets/TE_TPA_SharingExperience_Logo_Couleur-1.png ADDED
assets/TotalEnergies_TPA_picto_DegradeRouge_RVB.png ADDED
assets/favicon.png ADDED
assets/github-logo.png ADDED
assets/linkedin-logo-black.png ADDED
assets/linkedin-logo.png ADDED
assets/linkedin.png ADDED
assets/tough-communication.gif ADDED
config.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+
3
+ Config file for Streamlit App
4
+
5
+ """
6
+
7
+ from member import Member
8
+
9
+
10
+ TITLE = "ChatGPT"
11
+
12
+ TEAM_MEMBERS = [
13
+
14
+ Member(
15
+ name="Olivier Renouard",
16
+ linkedin_url="https://www.linkedin.com/in/olivier-renouard/",
17
+ github_url="https://github.com/Demosthene-OR",
18
+ )
19
+
20
+
21
+ ]
22
+
23
+ PROMOTION = "Playground ChatGPT - Octobre 2024"
member.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class Member:
2
+ def __init__(
3
+ self, name: str, linkedin_url: str = None, github_url: str = None
4
+ ) -> None:
5
+ self.name = name
6
+ self.linkedin_url = linkedin_url
7
+ self.github_url = github_url
8
+
9
+ def sidebar_markdown(self):
10
+
11
+ markdown = f'<b style="display: inline-block; vertical-align: middle; height: 100%">{self.name}</b>'
12
+ if self.linkedin_url is not None:
13
+ markdown += f' <a href={self.linkedin_url} target="_blank"><img src="https://dst-studio-template.s3.eu-west-3.amazonaws.com/linkedin-logo-black.png" alt="linkedin" width="25" style="vertical-align: middle; margin-left: 5px"/></a> '
14
+
15
+ if self.github_url is not None:
16
+ markdown += f' <a href={self.github_url} target="_blank"><img src="https://dst-studio-template.s3.eu-west-3.amazonaws.com/github-logo.png" alt="github" width="20" style="vertical-align: middle; margin-left: 5px"/></a> '
17
+ print(markdown)
18
+ return markdown
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ streamlit==1.34.0
2
+ pandas==2.2.2
3
+ ipython==8.27.0
4
+ numpy==1.26.4
5
+ https://files.pythonhosted.org/packages/cc/58/96aff0e5cb8b59c06232ea7e249ed902d04ec89f52636f5be06ceb0855fe/extra_streamlit_components-0.1.60-py3-none-any.whl
6
+ streamlit-option-menu==0.3.12
7
+ deep-translator==1.11.4
8
+ openai==0.27.8
9
+ python-dotenv==1.0.1
style.css ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ h1 {
2
+ padding-top: 0rem;
3
+ padding-bottom: 0rem;
4
+ margin-top:6px;
5
+ }
6
+ h2 {
7
+ padding-top: 0.75rem;
8
+ padding-bottom: 0.5rem;
9
+ }
10
+
11
+ h3 {
12
+ padding-bottom: 0.0rem;
13
+ }
14
+
15
+
16
+ /* La ligne suivante est nécessaire à cause du module streamlit_option_menu qui "casse" les CSS suivants */
17
+ @media (prefers-color-scheme: dark) {
18
+ .st-cc {
19
+ color: #fff!important; /* Couleur du texte en mode sombre */
20
+ }
21
+ .st-cg:hover {
22
+ color: rgb(255, 75, 75)!important; /* Couleur du texte en mode sombre */
23
+ }
24
+ section[data-testid="stSidebar"] .stSelectbox .st-cc {
25
+ color: rgb(255, 75, 75)!important;
26
+ font-weight: bold;
27
+ }
28
+ }
29
+
30
+ p {
31
+ margin-bottom:0.1rem;
32
+ }
33
+
34
+ code {
35
+ color: #1ec3bc;
36
+ }
37
+
38
+ #MainMenu {
39
+ display: none;
40
+ }
41
+
42
+ div[data-testid="stDecoration"] {
43
+ display: none;
44
+ }
45
+
46
+ footer {
47
+ display: none;
48
+ }
49
+
50
+ /* Radio buttons */
51
+
52
+ .st-cc {
53
+ color: black;
54
+ font-weight: 500;
55
+ }
56
+
57
+ /* Sidebar */
58
+
59
+ .css-1544g2n {
60
+ padding-top: 1rem;
61
+ }
62
+
63
+ .css-10oheav {
64
+ padding-top: 3rem;
65
+ }
66
+
67
+ .css-ue6h4q {
68
+ min-height: 0.5rem;
69
+ }
70
+
71
+ section[data-testid="stSidebar"] > div {
72
+ background-color: #10b8dd;
73
+ padding-top: 1rem;
74
+ padding-left: 0.5rem;
75
+ }
76
+
77
+ section[data-testid="stSidebar"] button[title="View fullscreen"] {
78
+ display: none;
79
+ }
80
+
81
+ section[data-testid="stSidebar"] button[kind="icon"] {
82
+ display: none;
83
+ }
84
+
85
+ section[data-testid="stSidebar"] .st-bk {
86
+ background-color: #10b8dd;
87
+ }
88
+
89
+ section[data-testid="stSidebar"] .st-c0 {
90
+ /* background-color: #10b8dd; */
91
+ }
92
+
93
+ section[data-testid="stSidebar"] hr {
94
+ margin-top: 30px;
95
+ border-color: white;
96
+ width: 50px;
97
+ }
98
+
99
+ section[data-testid="stSidebar"] h2 {
100
+ color: white;
101
+ }
102
+
103
+ section[data-testid="stSidebar"] .stSelectbox .st-bk {
104
+ background-color: #a0d3de;
105
+ }
106
+
107
+ section[data-testid="stSidebar"] .stSelectbox .st-cc {
108
+ color: rgb(255, 75, 75);
109
+ font-weight: bold;
110
+ }
111
+
112
+ /* Images */
113
+
114
+ button[title="View fullscreen"] {
115
+ display: none;
116
+ }
117
+
118
+ /* hr */
119
+
120
+ hr {
121
+ width: 700px;
122
+ border-width: 5px;
123
+ border-color: #10b8dd;
124
+ margin-top: 0px;
125
+ margin-bottom: 1em;
126
+ max-width: 100%;
127
+ }
128
+
129
+ /* First Page */
130
+
131
+ section[tabindex="0"] .block-container {
132
+ padding-top: 0px;
133
+ padding-bottom: 0px;
134
+ }
135
+
136
+ .st-emotion-cache-12fmjuu {
137
+ height: 0rem;
138
+ }
tabs/playground.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st # type: ignore
2
+ from translate_app import tr
3
+ import numpy as np
4
+ import openai
5
+ from dotenv import load_dotenv
6
+ import os
7
+ import warnings
8
+ warnings.filterwarnings('ignore')
9
+
10
+ if st.session_state.Cloud != 0:
11
+ load_dotenv()
12
+ os.getenv("OPENAI_API_KEY")
13
+ openai.api_key = os.environ["OPENAI_API_KEY"]
14
+
15
+ title = "Playground ChatGPT"
16
+ sidebar_name = "Playground"
17
+
18
+ def display_proba_next_token(prompt,temperature,max_token):
19
+
20
+ # Définir un ou plusieurs motifs d'arrêt
21
+ stop_sequences = [".","\n", "FIN", "Merci"] # Ajoutez d'autres motifs selon vos besoins
22
+ response = openai.Completion.create(
23
+ engine="davinci-002",
24
+ prompt=prompt,
25
+ max_tokens=max_token, # Limite à un seul token pour voir uniquement la probabilité du prochain
26
+ logprobs=5, # Obtenir les 5 tokens les plus probables
27
+ temperature=temperature, # Contrôle la créativité, 0 pour des réponses plus prédictibles
28
+ stop=stop_sequences
29
+ )
30
+
31
+ # Mettre logprobs dans un dictionnaire
32
+ if response['choices'][0]['text'] !="":
33
+ logprobs = response['choices'][0]['logprobs']['top_logprobs'][0]
34
+ logprobs_dict = dict(logprobs)
35
+
36
+ # Convertir logprobs en probabilités
37
+ probabilities = {key: np.exp(value) for key, value in logprobs_dict.items()}
38
+
39
+ # Afficher le texte de la réponse
40
+ st.write("Token suivant : ->"+list(probabilities.keys())[0]+"<-") # Afficher le texte de la réponse
41
+ # st.write("Texte de la réponse : ->"+response['choices'][0]['text'][0]+"<-") # Afficher le texte de la réponse
42
+ st.write("")
43
+
44
+ # Afficher les probabilités pour le prochain token
45
+ for token, proba in probabilities.items():
46
+ st.write(f"Token: ->{token}<- ; proba: {proba:.2f}")
47
+
48
+ # Afficher le texte de la réponse complete
49
+ st.write("")
50
+ try:
51
+ text = response['choices'][0]['text']
52
+ st.write("Texte de la réponse complète: ->" + str(text) + "<-")
53
+ except KeyError:
54
+ st.error("La réponse ne contient pas de texte supplémentaire.")
55
+ else:
56
+ st.error("La réponse ne contient pas de texte supplémentaire.")
57
+ # st.write("Texte de la réponse complete: ->"+str(response['choices'][0]['text'])+"<-") # Afficher le texte de la réponse
58
+ # st.write("")
59
+ # st.write(response)
60
+
61
+
62
+ def run():
63
+ global temperature, max_token
64
+
65
+ st.write("")
66
+ st.write("")
67
+ # TODO: choose between one of these GIFs
68
+ # st.image("https://dst-studio-template.s3.eu-west-3.amazonaws.com/1.gif")
69
+ # st.image("https://dst-studio-template.s3.eu-west-3.amazonaws.com/2.gif")
70
+ # st.image("https://dst-studio-template.s3.eu-west-3.amazonaws.com/3.gif")
71
+ # st.image("assets/tough-communication.gif",use_column_width=True)
72
+
73
+
74
+ # if st.session_state.Cloud == 0:
75
+ # st.image("assets/miss-honey-glasses-off.gif",use_column_width=True)
76
+ # else:
77
+ # st.image("https://media.tenor.com/pfOeAfytY98AAAAC/miss-honey-glasses-off.gif",use_column_width=True)
78
+
79
+ st.title(tr(title))
80
+ st.markdown('''
81
+ ---
82
+ ''')
83
+ st.header("**"+tr("Prédiction du token suivant")+"**")
84
+ st.markdown(tr(
85
+ """
86
+ Cet espace a pour objectif d'observer la génération de token par ChatGPT'
87
+ """)
88
+ , unsafe_allow_html=True)
89
+
90
+ try:
91
+ col1, col2 = st.columns([3, 1])
92
+ with col2:
93
+ temperature = st.slider(
94
+ label=tr("Temperature"),
95
+ min_value=0.0,
96
+ max_value=1.0,
97
+ value=0.0 # Valeur initiale
98
+ )
99
+ max_token = st.slider(
100
+ label=tr("Max tokens"),
101
+ min_value=1,
102
+ max_value=500,
103
+ value=100 # Valeur initiale
104
+ )
105
+ with col1:
106
+ prompt = st.text_area(label=tr("Prompt:"), value="La souris est mangée par le",height=100)
107
+ display_proba_next_token(prompt,temperature,max_token)
108
+ except Exception as e:
109
+ st.error(f"An unexpected error occurred: {e}")
110
+
111
+
112
+
113
+
114
+
115
+
translate_app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ # from translate import Translator
3
+ from deep_translator import GoogleTranslator
4
+
5
+ @st.cache_data(ttl="2d", show_spinner=False)
6
+ def trad(message,l):
7
+ try:
8
+ # Utilisation du module translate
9
+ # translator = Translator(to_lang=l , from_lang="fr")
10
+ # translation = translator.translate(message)
11
+
12
+ # Utilisation du module deep_translator
13
+ translation = GoogleTranslator(source='fr', target=l).translate(message.replace(" \n","§§§"))
14
+ translation = translation.replace("§§§"," \n") # .replace(" ","<br>")
15
+
16
+ return translation
17
+ except:
18
+ return "Problème de traduction.."
19
+
20
+ def tr(message):
21
+ if 'Language' not in st.session_state: l = 'fr'
22
+ else: l= st.session_state['Language']
23
+ if l == 'fr': return message
24
+ else: message = message.replace(":red[**","").replace("**]","")
25
+ return trad(message,l)
26
+
27
+