Demosthene-OR commited on
Commit
4d3b010
1 Parent(s): 510ea61
requirements.txt CHANGED
@@ -17,20 +17,14 @@ networkx==2.7.0
17
  transformers==4.37.2
18
  sentencepiece==0.1.99
19
  openai-whisper==20231117
20
- # tiktoken==0.6.0
21
  torch==2.2.0
22
  speechrecognition==3.10.1
23
  audio_recorder_streamlit==0.0.8
24
  whisper==1.1.10
25
  wavio==0.0.8
26
- # filesplit==4.0.1
27
  regex==2023.12.25
28
- # pydot==2.0.0
29
- # graphviz==0.20.1
30
  gTTS==2.5.1
31
  https://files.pythonhosted.org/packages/cc/58/96aff0e5cb8b59c06232ea7e249ed902d04ec89f52636f5be06ceb0855fe/extra_streamlit_components-0.1.60-py3-none-any.whl
32
  streamlit-option-menu==0.3.12
33
  deep-translator==1.11.4
34
- requests==2.27.0
35
- # asyncio==3.4.3
36
- # aiohttp==3.9.3
 
17
  transformers==4.37.2
18
  sentencepiece==0.1.99
19
  openai-whisper==20231117
 
20
  torch==2.2.0
21
  speechrecognition==3.10.1
22
  audio_recorder_streamlit==0.0.8
23
  whisper==1.1.10
24
  wavio==0.0.8
 
25
  regex==2023.12.25
 
 
26
  gTTS==2.5.1
27
  https://files.pythonhosted.org/packages/cc/58/96aff0e5cb8b59c06232ea7e249ed902d04ec89f52636f5be06ceb0855fe/extra_streamlit_components-0.1.60-py3-none-any.whl
28
  streamlit-option-menu==0.3.12
29
  deep-translator==1.11.4
30
+ requests==2.27.0
 
 
tabs/intro.py CHANGED
@@ -1,19 +1,9 @@
1
  import streamlit as st
2
  from translate_app import tr
3
- import pkg_resources
4
 
5
  title = "Démosthène"
6
  sidebar_name = "Introduction"
7
 
8
- def print_dependencies():
9
- # Récupérer toutes les distributions installées
10
- installed_packages = pkg_resources.working_set
11
-
12
- # Imprimer les dépendances avec leur version
13
- print("Dépendances avec leur version :")
14
- for package in installed_packages:
15
- print(f"{package.key}=={package.version}")
16
-
17
  def run():
18
 
19
  # TODO: choose between one of these GIFs
@@ -21,7 +11,7 @@ def run():
21
  # st.image("https://dst-studio-template.s3.eu-west-3.amazonaws.com/2.gif")
22
  # st.image("https://dst-studio-template.s3.eu-west-3.amazonaws.com/3.gif")
23
  # st.image("assets/tough-communication.gif",use_column_width=True)
24
- print_dependencies()
25
  st.write("")
26
  if st.session_state.Cloud == 0:
27
  st.image("assets/miss-honey-glasses-off.gif",use_column_width=True)
 
1
  import streamlit as st
2
  from translate_app import tr
 
3
 
4
  title = "Démosthène"
5
  sidebar_name = "Introduction"
6
 
 
 
 
 
 
 
 
 
 
7
  def run():
8
 
9
  # TODO: choose between one of these GIFs
 
11
  # st.image("https://dst-studio-template.s3.eu-west-3.amazonaws.com/2.gif")
12
  # st.image("https://dst-studio-template.s3.eu-west-3.amazonaws.com/3.gif")
13
  # st.image("assets/tough-communication.gif",use_column_width=True)
14
+
15
  st.write("")
16
  if st.session_state.Cloud == 0:
17
  st.image("assets/miss-honey-glasses-off.gif",use_column_width=True)
tabs/modelisation_seq2seq_tab.py CHANGED
@@ -4,29 +4,17 @@ import numpy as np
4
  import os
5
  from sacrebleu import corpus_bleu
6
  from transformers import pipeline
7
- # from translate import Translator
8
  from deep_translator import GoogleTranslator
9
  from audio_recorder_streamlit import audio_recorder
10
  import speech_recognition as sr
11
  import whisper
12
  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
21
- # from tensorflow.keras.utils import plot_model
22
- # from PIL import Image
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
@@ -77,37 +65,6 @@ def load_all_data():
77
  n1 = 0
78
  df_data_en, df_data_fr, translation_en_fr, translation_fr_en, lang_classifier, model_speech, finetuned_translation_en_fr = load_all_data()
79
 
80
- '''
81
- def display_translation3(n1, Lang,model_type):
82
- global df_data_src, df_data_tgt, placeholder
83
-
84
- placeholder = st.empty()
85
- with st.status(":sunglasses:", expanded=True):
86
- s = df_data_src.iloc[n1:n1+5][0].tolist()
87
- s_trad = []
88
- s_trad_ref = df_data_tgt.iloc[n1:n1+5][0].tolist()
89
- source = Lang[:2]
90
- target = Lang[-2:]
91
- for i in range(3):
92
- params = {"lang_tgt": target, "texte": s[i]}
93
- if model_type==1:
94
- # URL de votre endpoint FastAPI avec les paramètres de requête
95
- url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/rnn"
96
- else:
97
- # URL de votre endpoint FastAPI avec les paramètres de requête
98
- url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/transformer"
99
-
100
- # Envoie d'une requête GET avec les paramètres de requête
101
- response = requests.get(url, params=params)
102
- s_trad.append(response.json())
103
- st.write("**"+source+" :** :blue["+ s[i]+"]")
104
- st.write("**"+target+" :** "+s_trad[-1])
105
- st.write("**ref. :** "+s_trad_ref[i])
106
- st.write("")
107
- with placeholder:
108
- 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>", \
109
- unsafe_allow_html=True)
110
- '''
111
 
112
  def fetch_translation2(url):
113
  return requests.get(url)
@@ -130,12 +87,12 @@ def display_translation2(n1, Lang, model_type):
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:
135
  # Appels parallèles à fetch_translation avec les URLs
136
  responses = p.map(fetch_translation2, params)
137
  '''
138
-
139
  with concurrent.futures.ThreadPoolExecutor() as executor:
140
  # Appels parallèles à fetch_translation avec les URLs
141
  responses = list(executor.map(fetch_translation2, params))
@@ -157,51 +114,7 @@ def display_translation2(n1, Lang, model_type):
157
  st.write("<p style='text-align:center;background-color:red; color:white'>Score Bleu = "+str(int(round(score_bleu,0)))+"%</p>", \
158
  unsafe_allow_html=True)
159
 
160
-
161
- '''
162
- async def fetch_translation1(url, params):
163
- async with aiohttp.ClientSession() as session:
164
- async with session.get(url, params=params) as response:
165
- return await response.json()
166
-
167
- async def display_translation1(n1, Lang, model_type):
168
- global df_data_src, df_data_tgt, placeholder
169
-
170
- placeholder = st.empty()
171
- with st.status(":sunglasses:", expanded=True):
172
- s = df_data_src.iloc[n1:n1+5][0].tolist()
173
- s_trad = []
174
- s_trad_ref = df_data_tgt.iloc[n1:n1+5][0].tolist()
175
- source = Lang[:2]
176
- target = Lang[-2:]
177
-
178
- # Liste des tâches à exécuter en parallèle
179
- tasks = []
180
- for i in range(3):
181
- params = {"lang_tgt": target, "texte": s[i]}
182
- if model_type == 1:
183
- url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/rnn"
184
- else:
185
- url = "https://demosthene-or-api-avr23-cds-translation.hf.space/small_vocab/transformer"
186
-
187
- # Ajout de la tâche à la liste des tâches
188
- tasks.append(fetch_translation1(url, params))
189
-
190
- # Exécution des tâches en parallèle
191
- responses = await asyncio.gather(*tasks)
192
-
193
- for i, response in enumerate(responses):
194
- s_trad.append(response)
195
- st.write("**"+source+" :** :blue["+ s[i]+"]")
196
- st.write("**"+target+" :** "+s_trad[-1])
197
- st.write("**ref. :** "+s_trad_ref[i])
198
- st.write("")
199
-
200
- with placeholder:
201
- 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>", \
202
- unsafe_allow_html=True)
203
- '''
204
-
205
  @st.cache_data
206
  def find_lang_label(lang_sel):
207
  global lang_tgt, label_lang
@@ -385,7 +298,6 @@ def run():
385
  with col2:
386
  st.write(":red[**Trad. Google Translate**]")
387
  try:
388
- # translator = Translator(to_lang=l_tgt, from_lang=Lang_detected)
389
  translator = GoogleTranslator(source=Lang_detected, target=l_tgt)
390
  if custom_sentence!="":
391
  translation = translator.translate(custom_sentence)
 
4
  import os
5
  from sacrebleu import corpus_bleu
6
  from transformers import pipeline
 
7
  from deep_translator import GoogleTranslator
8
  from audio_recorder_streamlit import audio_recorder
9
  import speech_recognition as sr
10
  import whisper
11
  import io
12
  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
 
65
  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)
 
87
  else:
88
  url = f"{url_base[i]}/small_vocab/transformer?lang_tgt={target}&texte={s[i]}"
89
  params.append(url)
90
+
91
  '''
92
  with Pool(n) as p:
93
  # Appels parallèles à fetch_translation avec les URLs
94
  responses = p.map(fetch_translation2, params)
95
  '''
 
96
  with concurrent.futures.ThreadPoolExecutor() as executor:
97
  # Appels parallèles à fetch_translation avec les URLs
98
  responses = list(executor.map(fetch_translation2, params))
 
114
  st.write("<p style='text-align:center;background-color:red; color:white'>Score Bleu = "+str(int(round(score_bleu,0)))+"%</p>", \
115
  unsafe_allow_html=True)
116
 
117
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  @st.cache_data
119
  def find_lang_label(lang_sel):
120
  global lang_tgt, label_lang
 
298
  with col2:
299
  st.write(":red[**Trad. Google Translate**]")
300
  try:
 
301
  translator = GoogleTranslator(source=Lang_detected, target=l_tgt)
302
  if custom_sentence!="":
303
  translation = translator.translate(custom_sentence)