Demosthene-OR commited on
Commit
9910446
1 Parent(s): bb0fb0e
tabs/id_lang_tab.py CHANGED
@@ -13,6 +13,7 @@ import seaborn as sns
13
  from sklearn import naive_bayes
14
  from translate_app import tr
15
  import requests
 
16
 
17
  title = "Identification de langue"
18
  sidebar_name = "Identification de langue"
@@ -280,11 +281,11 @@ def display_shapley(lang_sel):
280
  def run():
281
  global tokenizer, vectorizer, dict_token, dict_ids, nb_token, lan_to_language, clf_nb
282
  global toggle_val, custom_sentence, lan_identified
283
- global lang_exemples, exemples
284
 
285
-
286
  tokenizer, dict_token, dict_ids, nb_token, lan_to_language, clf_nb, vectorizer = init_nb_identifier()
287
- lan_identified = requests.get( "https://demosthene-or-api-avr23-cds-translation.hf.space/lan_identified").json()
288
  lang_id_model_ext, dict_xlmr, sentence_test, lang_exemples, exemples= init_lang_id_external()
289
 
290
  st.write("")
@@ -329,7 +330,7 @@ def run():
329
 
330
  if custom_sentence!='':
331
 
332
- url = "https://demosthene-or-api-avr23-cds-translation.hf.space/lang_id_dl"
333
  params = {"sentence": custom_sentence}
334
  response = requests.get(url, params=params)
335
 
@@ -409,7 +410,8 @@ def run():
409
  st.write("<center><h5>"+tr("Architecture du modèle utilisé")+":</h5></center>", unsafe_allow_html=True)
410
  col1, col2, col3 = st.columns([0.15,0.7,0.15])
411
  with col2:
412
- st.image("https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/plot_model?&model_type=lang_id",use_column_width="auto")
 
413
  elif (chosen_id == "tab3"):
414
  st.write("### **"+tr("Interpretabilité du classifieur Naïve Bayes sur 5 langues")+"**")
415
  st.write("##### "+tr("..et un Training set réduit (15000 phrases et 94 tokens)"))
 
13
  from sklearn import naive_bayes
14
  from translate_app import tr
15
  import requests
16
+ import read_api_url
17
 
18
  title = "Identification de langue"
19
  sidebar_name = "Identification de langue"
 
281
  def run():
282
  global tokenizer, vectorizer, dict_token, dict_ids, nb_token, lan_to_language, clf_nb
283
  global toggle_val, custom_sentence, lan_identified
284
+ global lang_exemples, exemples, url_base
285
 
286
+ url_base = read_api_url()
287
  tokenizer, dict_token, dict_ids, nb_token, lan_to_language, clf_nb, vectorizer = init_nb_identifier()
288
+ lan_identified = requests.get( url_base[0]+"/lan_identified").json()
289
  lang_id_model_ext, dict_xlmr, sentence_test, lang_exemples, exemples= init_lang_id_external()
290
 
291
  st.write("")
 
330
 
331
  if custom_sentence!='':
332
 
333
+ url = url_base[0]+"/lang_id_dl"
334
  params = {"sentence": custom_sentence}
335
  response = requests.get(url, params=params)
336
 
 
410
  st.write("<center><h5>"+tr("Architecture du modèle utilisé")+":</h5></center>", unsafe_allow_html=True)
411
  col1, col2, col3 = st.columns([0.15,0.7,0.15])
412
  with col2:
413
+
414
+ st.image(url_base[0]+"e/small_vocab/plot_model?&model_type=lang_id",use_column_width="auto")
415
  elif (chosen_id == "tab3"):
416
  st.write("### **"+tr("Interpretabilité du classifieur Naïve Bayes sur 5 langues")+"**")
417
  st.write("##### "+tr("..et un Training set réduit (15000 phrases et 94 tokens)"))
tabs/modelisation_seq2seq_tab.py CHANGED
@@ -13,33 +13,17 @@ import wavio
13
  from gtts import gTTS
14
  from extra_streamlit_components import tab_bar, TabBarItemData
15
  from translate_app import tr
16
- import csv
17
  import requests
18
  # from multiprocessing import Pool
19
  import concurrent.futures
20
- import time
21
-
22
 
23
  title = "Traduction Sequence à Sequence"
24
  sidebar_name = "Traduction Seq2Seq"
25
  dataPath = st.session_state.DataPath
26
 
27
- @st.cache_data
28
- def read_api_url():
29
-
30
- api_url = []
31
- # Ouvrir le fichier CSV en mode lecture
32
- with open("api-url.txt", newline='') as fichier_csv:
33
- lecteur_csv = csv.reader(fichier_csv)
34
-
35
- # Lire et afficher les trois premières lignes
36
- for i in range(3):
37
- ligne = next(lecteur_csv, None) # Lire la ligne suivante
38
- if ligne is not None:
39
- api_url.append(ligne[0])
40
- else: return None
41
- return api_url
42
-
43
  @st.cache_data
44
  def load_corpus(path):
45
  input_file = os.path.join(path)
@@ -66,10 +50,10 @@ n1 = 0
66
  df_data_en, df_data_fr, translation_en_fr, translation_fr_en, lang_classifier, model_speech, finetuned_translation_en_fr = load_all_data()
67
 
68
 
69
- def fetch_translation2(url):
70
  return requests.get(url)
71
 
72
- def display_translation2(n1, Lang, model_type):
73
  global df_data_src, df_data_tgt, placeholder, url_base
74
 
75
  n = 3
@@ -215,23 +199,11 @@ def run():
215
  mode = 2 # Transformer
216
 
217
  # Exécuter la fonction asynchrone
218
- '''
219
- t0 = time.time()
220
- asyncio.run(display_translation1(n1, Lang, mode))
221
- t1 = time.time()
222
- st.write("Durée 1: "+str(t1-t0))
223
- '''
224
  # t0 = time.time()
225
- display_translation2(n1, Lang,mode)
226
  # t1 = time.time()
227
- # st.write("Durée 2: "+str(t1-t0))
228
- '''
229
- t0 = time.time()
230
- display_translation3(n1, Lang,mode)
231
- t1 = time.time()
232
- st.write("Durée 3: "+str(t1-t0))
233
- '''
234
-
235
  st.write("## **"+tr("Details sur la méthode")+" :**\n")
236
  if (chosen_id == "tab1"):
237
  st.markdown(tr(
 
13
  from gtts import gTTS
14
  from extra_streamlit_components import tab_bar, TabBarItemData
15
  from translate_app import tr
16
+ # import csv
17
  import requests
18
  # from multiprocessing import Pool
19
  import concurrent.futures
20
+ # import time
21
+ import read_api_url
22
 
23
  title = "Traduction Sequence à Sequence"
24
  sidebar_name = "Traduction Seq2Seq"
25
  dataPath = st.session_state.DataPath
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  @st.cache_data
28
  def load_corpus(path):
29
  input_file = os.path.join(path)
 
50
  df_data_en, df_data_fr, translation_en_fr, translation_fr_en, lang_classifier, model_speech, finetuned_translation_en_fr = load_all_data()
51
 
52
 
53
+ def fetch_translation(url):
54
  return requests.get(url)
55
 
56
+ def display_translation(n1, Lang, model_type):
57
  global df_data_src, df_data_tgt, placeholder, url_base
58
 
59
  n = 3
 
199
  mode = 2 # Transformer
200
 
201
  # Exécuter la fonction asynchrone
 
 
 
 
 
 
202
  # t0 = time.time()
203
+ display_translation(n1, Lang,mode)
204
  # t1 = time.time()
205
+ # st.write("Durée : "+str(t1-t0))
206
+
 
 
 
 
 
 
207
  st.write("## **"+tr("Details sur la méthode")+" :**\n")
208
  if (chosen_id == "tab1"):
209
  st.markdown(tr(
tabs/read_api_url.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+
3
+ @st.cache_data
4
+ def read_api_url():
5
+
6
+ api_url = []
7
+ # Ouvrir le fichier CSV en mode lecture
8
+ with open("api-url.txt", newline='') as fichier_csv:
9
+ lecteur_csv = csv.reader(fichier_csv)
10
+
11
+ # Lire toutes les lignes
12
+ ligne = next(lecteur_csv, None)
13
+ while ligne is not None:
14
+ api_url.append(ligne[0])
15
+ ligne = next(lecteur_csv, None)
16
+
17
+ return api_url