Commit
•
4eea31c
1
Parent(s):
7a6baf9
Update modelisation_seq2seq_tab.py
Browse files
tabs/modelisation_seq2seq_tab.py
CHANGED
@@ -275,7 +275,7 @@ n1 = 0
|
|
275 |
df_data_en, df_data_fr, translation_en_fr, translation_fr_en, lang_classifier, model_speech, rnn_en_fr, rnn_fr_en,\
|
276 |
transformer_en_fr, transformer_fr_en, finetuned_translation_en_fr = load_all_data()
|
277 |
|
278 |
-
|
279 |
def display_translation(n1, Lang,model_type):
|
280 |
global df_data_src, df_data_tgt, placeholder
|
281 |
|
@@ -305,43 +305,7 @@ def display_translation(n1, Lang,model_type):
|
|
305 |
with placeholder:
|
306 |
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>", \
|
307 |
unsafe_allow_html=True)
|
308 |
-
'''
|
309 |
-
'''
|
310 |
-
def display_translation(n1, Lang,model_type):
|
311 |
-
global df_data_src, df_data_tgt, placeholder
|
312 |
-
|
313 |
-
async def decode_seq_all(model_type,s, target):
|
314 |
-
s_trad = []
|
315 |
-
for i in range(3):
|
316 |
-
params = {"lang_tgt": target, "texte": s[i]}
|
317 |
-
if model_type==1:
|
318 |
-
# URL de votre endpoint FastAPI avec les paramètres de requête
|
319 |
-
url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/rnn"
|
320 |
-
else:
|
321 |
-
# URL de votre endpoint FastAPI avec les paramètres de requête
|
322 |
-
url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/transformer"
|
323 |
|
324 |
-
# Envoie d'une requête GET avec les paramètres de requête
|
325 |
-
await s_trad.append(requests.get(url, params=params).json())
|
326 |
-
# await (len(s_trad) == 3)
|
327 |
-
return s_trad
|
328 |
-
|
329 |
-
placeholder = st.empty()
|
330 |
-
with st.status(":sunglasses:", expanded=True):
|
331 |
-
s = df_data_src.iloc[n1:n1+5][0].tolist()
|
332 |
-
s_trad = []
|
333 |
-
s_trad_ref = df_data_tgt.iloc[n1:n1+5][0].tolist()
|
334 |
-
source = Lang[:2]
|
335 |
-
target = Lang[-2:]
|
336 |
-
s_trad = decode_seq_all(model_type,s, target)
|
337 |
-
for i in range(3):
|
338 |
-
st.write("**"+source+" :** :blue["+ s[i]+"]")
|
339 |
-
st.write("**"+target+" :** "+s_trad[i])
|
340 |
-
st.write("**ref. :** "+s_trad_ref[i])
|
341 |
-
st.write("")
|
342 |
-
with placeholder:
|
343 |
-
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>", \
|
344 |
-
unsafe_allow_html=True)
|
345 |
'''
|
346 |
async def fetch_translation(url, params):
|
347 |
a = str(time.time())
|
@@ -387,7 +351,7 @@ async def display_translation(n1, Lang, model_type):
|
|
387 |
with placeholder:
|
388 |
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>", \
|
389 |
unsafe_allow_html=True)
|
390 |
-
|
391 |
|
392 |
|
393 |
@st.cache_data
|
@@ -493,15 +457,15 @@ def run():
|
|
493 |
if (chosen_id == "tab1"):
|
494 |
t0 = time.time()
|
495 |
# Exécuter la fonction asynchrone
|
496 |
-
asyncio.run(display_translation(n1, Lang, 1))
|
497 |
-
|
498 |
t1 = time.time()
|
499 |
st.write("Durée: "+str(t1-t0))
|
500 |
else:
|
501 |
t0 = time.time()
|
502 |
# Exécuter la fonction asynchrone
|
503 |
-
asyncio.run(display_translation(n1, Lang, 2))
|
504 |
-
|
505 |
t1 = time.time()
|
506 |
st.write("Durée: "+str(t1-t0))
|
507 |
|
|
|
275 |
df_data_en, df_data_fr, translation_en_fr, translation_fr_en, lang_classifier, model_speech, rnn_en_fr, rnn_fr_en,\
|
276 |
transformer_en_fr, transformer_fr_en, finetuned_translation_en_fr = load_all_data()
|
277 |
|
278 |
+
|
279 |
def display_translation(n1, Lang,model_type):
|
280 |
global df_data_src, df_data_tgt, placeholder
|
281 |
|
|
|
305 |
with placeholder:
|
306 |
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>", \
|
307 |
unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
'''
|
310 |
async def fetch_translation(url, params):
|
311 |
a = str(time.time())
|
|
|
351 |
with placeholder:
|
352 |
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>", \
|
353 |
unsafe_allow_html=True)
|
354 |
+
'''
|
355 |
|
356 |
|
357 |
@st.cache_data
|
|
|
457 |
if (chosen_id == "tab1"):
|
458 |
t0 = time.time()
|
459 |
# Exécuter la fonction asynchrone
|
460 |
+
# asyncio.run(display_translation(n1, Lang, 1))
|
461 |
+
display_translation(n1, Lang,1)
|
462 |
t1 = time.time()
|
463 |
st.write("Durée: "+str(t1-t0))
|
464 |
else:
|
465 |
t0 = time.time()
|
466 |
# Exécuter la fonction asynchrone
|
467 |
+
# asyncio.run(display_translation(n1, Lang, 2))
|
468 |
+
display_translation(n1, Lang,2)
|
469 |
t1 = time.time()
|
470 |
st.write("Durée: "+str(t1-t0))
|
471 |
|