Demosthene-OR commited on
Commit
54e1725
1 Parent(s): 93bd335
Files changed (2) hide show
  1. packages.txt +1 -2
  2. tabs/modelisation_seq2seq_tab.py +28 -15
packages.txt CHANGED
@@ -1,5 +1,4 @@
1
  build-essential
2
  libasound-dev
3
  portaudio19-dev
4
- python3-pyaudio
5
- graphviz
 
1
  build-essential
2
  libasound-dev
3
  portaudio19-dev
4
+ python3-pyaudio
 
tabs/modelisation_seq2seq_tab.py CHANGED
@@ -13,8 +13,8 @@ import io
13
  import wavio
14
  # from filesplit.merge import Merge
15
  # import tensorflow as tf
16
- import string
17
- import re
18
  # from tensorflow import keras
19
  # from keras_nlp.layers import TransformerEncoder
20
  # from tensorflow.keras import layers
@@ -23,17 +23,35 @@ import re
23
  from gtts import gTTS
24
  from extra_streamlit_components import tab_bar, TabBarItemData
25
  from translate_app import tr
 
26
  import requests
27
  # import asyncio
28
  # import aiohttp
29
- from multiprocessing import Pool
30
  import concurrent.futures
31
  import time
32
 
 
33
  title = "Traduction Sequence à Sequence"
34
  sidebar_name = "Traduction Seq2Seq"
35
  dataPath = st.session_state.DataPath
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  @st.cache_data
38
  def load_corpus(path):
39
  input_file = os.path.join(path)
@@ -95,7 +113,7 @@ def fetch_translation2(url):
95
  return requests.get(url)
96
 
97
  def display_translation2(n1, Lang, model_type):
98
- global df_data_src, df_data_tgt, placeholder
99
 
100
  n = 3
101
  placeholder = st.empty()
@@ -106,17 +124,11 @@ def display_translation2(n1, Lang, model_type):
106
  source = Lang[:2]
107
  target = Lang[-2:]
108
  params = []
109
- if model_type == 1:
110
- url_base = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/rnn"
111
- else:
112
- url_base = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/transformer"
113
  for i in range(n):
114
- # Construction de l'URL avec les paramètres
115
- # url = f"{url_base}{i}?lang_tgt={target}&texte={s[i]}"
116
  if model_type == 1:
117
- url = f"https://demosthene-or-api-avr23-cds-translation{i+1}.hf.space/small_vocab/rnn?lang_tgt={target}&texte={s[i]}"
118
  else:
119
- url = f"https://demosthene-or-api-avr23-cds-translation{i+1}.hf.space/small_vocab/transformer?lang_tgt={target}&texte={s[i]}"
120
  params.append(url)
121
  '''
122
  with Pool(n) as p:
@@ -215,7 +227,7 @@ def run():
215
 
216
  global n1, df_data_src, df_data_tgt, placeholder, model_speech
217
  global df_data_en, df_data_fr, lang_classifier, translation_en_fr, translation_fr_en
218
- global lang_tgt, label_lang
219
 
220
  st.write("")
221
  st.title(tr(title))
@@ -261,6 +273,7 @@ def run():
261
  default="tab1")
262
 
263
  if (chosen_id == "tab1") or (chosen_id == "tab2") :
 
264
  if (chosen_id == "tab1"):
265
  st.write("<center><h5><b>"+tr("Schéma d'un Réseau de Neurones Récurrents")+"</b></h5></center>", unsafe_allow_html=True)
266
  st.image("assets/deepnlp_graph3.png",use_column_width=True)
@@ -329,9 +342,9 @@ def run():
329
  , unsafe_allow_html=True)
330
  st.write("<center><h5>"+tr("Architecture du modèle utilisé")+":</h5>", unsafe_allow_html=True)
331
  if (chosen_id == "tab1"):
332
- st.image("https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/plot_model?lang_tgt="+Lang[-2:]+"&model_type=rnn",use_column_width=True)
333
  else:
334
- st.image("https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/plot_model?lang_tgt="+Lang[-2:]+"&model_type=transformer",use_column_width=True)
335
 
336
  st.write("</center>", unsafe_allow_html=True)
337
 
 
13
  import wavio
14
  # from filesplit.merge import Merge
15
  # import tensorflow as tf
16
+ # import string
17
+ # import re
18
  # from tensorflow import keras
19
  # from keras_nlp.layers import TransformerEncoder
20
  # from tensorflow.keras import layers
 
23
  from gtts import gTTS
24
  from extra_streamlit_components import tab_bar, TabBarItemData
25
  from translate_app import tr
26
+ import csv
27
  import requests
28
  # import asyncio
29
  # import aiohttp
30
+ # from multiprocessing import Pool
31
  import concurrent.futures
32
  import time
33
 
34
+
35
  title = "Traduction Sequence à Sequence"
36
  sidebar_name = "Traduction Seq2Seq"
37
  dataPath = st.session_state.DataPath
38
 
39
+ @st.cache_data
40
+ def read_api_url():
41
+
42
+ api_url = []
43
+ # Ouvrir le fichier CSV en mode lecture
44
+ with open("api-url.txt", newline='') as fichier_csv:
45
+ lecteur_csv = csv.reader(fichier_csv)
46
+
47
+ # Lire et afficher les trois premières lignes
48
+ for i in range(3):
49
+ ligne = next(lecteur_csv, None) # Lire la ligne suivante
50
+ if ligne is not None:
51
+ api_url.append(ligne)
52
+ else: return None
53
+ return api_url
54
+
55
  @st.cache_data
56
  def load_corpus(path):
57
  input_file = os.path.join(path)
 
113
  return requests.get(url)
114
 
115
  def display_translation2(n1, Lang, model_type):
116
+ global df_data_src, df_data_tgt, placeholder, url_base
117
 
118
  n = 3
119
  placeholder = st.empty()
 
124
  source = Lang[:2]
125
  target = Lang[-2:]
126
  params = []
 
 
 
 
127
  for i in range(n):
 
 
128
  if model_type == 1:
129
+ url = f"{url_base[i]}/small_vocab/rnn?lang_tgt={target}&texte={s[i]}"
130
  else:
131
+ url = f"{url_base[i]}/small_vocab/transformer?lang_tgt={target}&texte={s[i]}"
132
  params.append(url)
133
  '''
134
  with Pool(n) as p:
 
227
 
228
  global n1, df_data_src, df_data_tgt, placeholder, model_speech
229
  global df_data_en, df_data_fr, lang_classifier, translation_en_fr, translation_fr_en
230
+ global lang_tgt, label_lang, url_base
231
 
232
  st.write("")
233
  st.title(tr(title))
 
273
  default="tab1")
274
 
275
  if (chosen_id == "tab1") or (chosen_id == "tab2") :
276
+ url_base = read_api_url()
277
  if (chosen_id == "tab1"):
278
  st.write("<center><h5><b>"+tr("Schéma d'un Réseau de Neurones Récurrents")+"</b></h5></center>", unsafe_allow_html=True)
279
  st.image("assets/deepnlp_graph3.png",use_column_width=True)
 
342
  , unsafe_allow_html=True)
343
  st.write("<center><h5>"+tr("Architecture du modèle utilisé")+":</h5>", unsafe_allow_html=True)
344
  if (chosen_id == "tab1"):
345
+ st.image(url_base[0]+"/small_vocab/plot_model?lang_tgt="+Lang[-2:]+"&model_type=rnn",use_column_width=True)
346
  else:
347
+ st.image(url_base[0]+"/small_vocab/plot_model?lang_tgt="+Lang[-2:]+"&model_type=transformer",use_column_width=True)
348
 
349
  st.write("</center>", unsafe_allow_html=True)
350