Demosthene-OR commited on
Commit
ccc79f3
1 Parent(s): d30c148
requirements.txt CHANGED
@@ -35,3 +35,4 @@ streamlit-option-menu==0.3.12
35
  deep-translator==1.11.4
36
  requests==2.27.0
37
  asyncio
 
 
35
  deep-translator==1.11.4
36
  requests==2.27.0
37
  asyncio
38
+ aiohttp
tabs/modelisation_seq2seq_tab.py CHANGED
@@ -25,6 +25,7 @@ from extra_streamlit_components import tab_bar, TabBarItemData
25
  from translate_app import tr
26
  import requests
27
  import asyncio
 
28
 
29
  title = "Traduction Sequence à Sequence"
30
  sidebar_name = "Traduction Seq2Seq"
@@ -304,6 +305,7 @@ def display_translation(n1, Lang,model_type):
304
  st.write("<p style='text-align:center;background-color:red; color:white')>Score Bleu = "+str(int(round(corpus_bleu(s_trad,[s_trad_ref]).score,0)))+"%</p>", \
305
  unsafe_allow_html=True)
306
  '''
 
307
  def display_translation(n1, Lang,model_type):
308
  global df_data_src, df_data_tgt, placeholder
309
 
@@ -339,6 +341,50 @@ def display_translation(n1, Lang,model_type):
339
  with placeholder:
340
  st.write("<p style='text-align:center;background-color:red; color:white')>Score Bleu = "+str(int(round(corpus_bleu(s_trad,[s_trad_ref]).score,0)))+"%</p>", \
341
  unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
 
343
  @st.cache_data
344
  def find_lang_label(lang_sel):
@@ -441,9 +487,13 @@ def run():
441
 
442
  st.write("## **"+tr("Résultats")+" :**\n")
443
  if (chosen_id == "tab1"):
444
- display_translation(n1, Lang,1)
 
 
445
  else:
446
- display_translation(n1, Lang,2)
 
 
447
 
448
  st.write("## **"+tr("Details sur la méthode")+" :**\n")
449
  if (chosen_id == "tab1"):
 
25
  from translate_app import tr
26
  import requests
27
  import asyncio
28
+ import aiohttp
29
 
30
  title = "Traduction Sequence à Sequence"
31
  sidebar_name = "Traduction Seq2Seq"
 
305
  st.write("<p style='text-align:center;background-color:red; color:white')>Score Bleu = "+str(int(round(corpus_bleu(s_trad,[s_trad_ref]).score,0)))+"%</p>", \
306
  unsafe_allow_html=True)
307
  '''
308
+ '''
309
  def display_translation(n1, Lang,model_type):
310
  global df_data_src, df_data_tgt, placeholder
311
 
 
341
  with placeholder:
342
  st.write("<p style='text-align:center;background-color:red; color:white')>Score Bleu = "+str(int(round(corpus_bleu(s_trad,[s_trad_ref]).score,0)))+"%</p>", \
343
  unsafe_allow_html=True)
344
+ '''
345
+ async def fetch_translation(url, params):
346
+ async with aiohttp.ClientSession() as session:
347
+ async with session.get(url, params=params) as response:
348
+ return await response.json()
349
+
350
+ async def display_translation(n1, Lang, model_type):
351
+ global df_data_src, df_data_tgt, placeholder
352
+
353
+ placeholder = st.empty()
354
+ with st.status(":sunglasses:", expanded=True):
355
+ s = df_data_src.iloc[n1:n1+5][0].tolist()
356
+ s_trad = []
357
+ s_trad_ref = df_data_tgt.iloc[n1:n1+5][0].tolist()
358
+ source = Lang[:2]
359
+ target = Lang[-2:]
360
+
361
+ # Liste des tâches à exécuter en parallèle
362
+ tasks = []
363
+ for i in range(3):
364
+ params = {"lang_tgt": target, "texte": s[i]}
365
+ if model_type == 1:
366
+ url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/rnn"
367
+ else:
368
+ url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/transformer"
369
+
370
+ # Ajout de la tâche à la liste des tâches
371
+ tasks.append(fetch_translation(url, params))
372
+
373
+ # Exécution des tâches en parallèle
374
+ responses = await asyncio.gather(*tasks)
375
+
376
+ for i, response in enumerate(responses):
377
+ s_trad.append(response)
378
+ st.write("**"+source+" :** :blue["+ s[i]+"]")
379
+ st.write("**"+target+" :** "+s_trad[-1])
380
+ st.write("**ref. :** "+s_trad_ref[i])
381
+ st.write("")
382
+
383
+ with placeholder:
384
+ st.write("<p style='text-align:center;background-color:red; color:white')>Score Bleu = "+str(int(round(corpus_bleu(s_trad,[s_trad_ref]).score,0)))+"%</p>", \
385
+ unsafe_allow_html=True)
386
+
387
+
388
 
389
  @st.cache_data
390
  def find_lang_label(lang_sel):
 
487
 
488
  st.write("## **"+tr("Résultats")+" :**\n")
489
  if (chosen_id == "tab1"):
490
+ # Exécuter la fonction asynchrone
491
+ asyncio.run(display_translation(n1, Lang, 1))
492
+ # display_translation(n1, Lang,1)
493
  else:
494
+ # Exécuter la fonction asynchrone
495
+ asyncio.run(display_translation(n1, Lang, 2))
496
+ # display_translation(n1, Lang,2)
497
 
498
  st.write("## **"+tr("Details sur la méthode")+" :**\n")
499
  if (chosen_id == "tab1"):