Demosthene-OR commited on
Commit
42b91da
1 Parent(s): 21cc31e
requirements.txt CHANGED
@@ -36,3 +36,4 @@ deep-translator==1.11.4
36
  requests==2.27.0
37
  asyncio
38
  aiohttp
 
 
36
  requests==2.27.0
37
  asyncio
38
  aiohttp
39
+ multiprocessing
tabs/modelisation_seq2seq_tab.py CHANGED
@@ -26,6 +26,7 @@ from translate_app import tr
26
  import requests
27
  import asyncio
28
  import aiohttp
 
29
  import time
30
 
31
  title = "Traduction Sequence à Sequence"
@@ -88,7 +89,41 @@ def display_translation(n1, Lang,model_type):
88
  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>", \
89
  unsafe_allow_html=True)
90
  '''
91
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  async def fetch_translation(url, params):
93
  async with aiohttp.ClientSession() as session:
94
  async with session.get(url, params=params) as response:
@@ -130,7 +165,7 @@ async def display_translation(n1, Lang, model_type):
130
  with placeholder:
131
  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>", \
132
  unsafe_allow_html=True)
133
-
134
 
135
 
136
  @st.cache_data
@@ -229,15 +264,15 @@ def run():
229
  if (chosen_id == "tab1"):
230
  t0 = time.time()
231
  # Exécuter la fonction asynchrone
232
- asyncio.run(display_translation(n1, Lang, 1))
233
- # display_translation(n1, Lang,1)
234
  t1 = time.time()
235
  st.write("Durée: "+str(t1-t0))
236
  else:
237
  t0 = time.time()
238
  # Exécuter la fonction asynchrone
239
- asyncio.run(display_translation(n1, Lang, 2))
240
- # display_translation(n1, Lang,2)
241
  t1 = time.time()
242
  st.write("Durée: "+str(t1-t0))
243
 
 
26
  import requests
27
  import asyncio
28
  import aiohttp
29
+ from multiprocessing import Pool
30
  import time
31
 
32
  title = "Traduction Sequence à Sequence"
 
89
  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>", \
90
  unsafe_allow_html=True)
91
  '''
92
+
93
+ def display_translation(n1, Lang,model_type):
94
+ global df_data_src, df_data_tgt, placeholder
95
+
96
+ placeholder = st.empty()
97
+ with st.status(":sunglasses:", expanded=True):
98
+ s = df_data_src.iloc[n1:n1+5][0].tolist()
99
+ s_trad = []
100
+ s_trad_ref = df_data_tgt.iloc[n1:n1+5][0].tolist()
101
+ source = Lang[:2]
102
+ target = Lang[-2:]
103
+ params = []
104
+ if model_type==1:
105
+ # URL de votre endpoint FastAPI avec les paramètres de requête
106
+ url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/rnn"
107
+ else:
108
+ # URL de votre endpoint FastAPI avec les paramètres de requête
109
+ url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/transformer"
110
+ for i in range(3):
111
+ # Ajout du parametre à la liste des parametres
112
+ params.append(url+"?lang_tgt="+target+"&texte="+s[i])
113
+
114
+ with Pool(3) as p:
115
+ responses = p.map(requests.get, params)
116
+
117
+ for i in range(3):
118
+ s_trad.append(responses[i].json())
119
+ st.write("**"+source+" :** :blue["+ s[i]+"]")
120
+ st.write("**"+target+" :** "+s_trad[-1])
121
+ st.write("**ref. :** "+s_trad_ref[i])
122
+ st.write("")
123
+ with placeholder:
124
+ 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>", \
125
+ unsafe_allow_html=True)
126
+ '''
127
  async def fetch_translation(url, params):
128
  async with aiohttp.ClientSession() as session:
129
  async with session.get(url, params=params) as response:
 
165
  with placeholder:
166
  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>", \
167
  unsafe_allow_html=True)
168
+ '''
169
 
170
 
171
  @st.cache_data
 
264
  if (chosen_id == "tab1"):
265
  t0 = time.time()
266
  # Exécuter la fonction asynchrone
267
+ # asyncio.run(display_translation(n1, Lang, 1))
268
+ display_translation(n1, Lang,1)
269
  t1 = time.time()
270
  st.write("Durée: "+str(t1-t0))
271
  else:
272
  t0 = time.time()
273
  # Exécuter la fonction asynchrone
274
+ # asyncio.run(display_translation(n1, Lang, 2))
275
+ display_translation(n1, Lang,2)
276
  t1 = time.time()
277
  st.write("Durée: "+str(t1-t0))
278