Spaces:
Sleeping
Sleeping
Commit
·
394de27
1
Parent(s):
745765c
new setting and test of our model
Browse files
lambdaAPI/__pycache__/settings.cpython-310.pyc
CHANGED
|
Binary files a/lambdaAPI/__pycache__/settings.cpython-310.pyc and b/lambdaAPI/__pycache__/settings.cpython-310.pyc differ
|
|
|
lambdaAPI/settings.py
CHANGED
|
@@ -110,12 +110,13 @@ AUTH_PASSWORD_VALIDATORS = [
|
|
| 110 |
},
|
| 111 |
]
|
| 112 |
|
| 113 |
-
ALLOWED_HOSTS = ['127.0.0.1','https://ferdinandpycode-lambda-hf.hf.space','http://localhost']
|
| 114 |
|
| 115 |
CORS_ALLOWED_ORIGINS = [
|
| 116 |
"http://localhost",
|
| 117 |
"https://ferdinandpycode-lambda-hf.hf.space",
|
| 118 |
"http://127.0.0.1",
|
|
|
|
| 119 |
]
|
| 120 |
|
| 121 |
|
|
|
|
| 110 |
},
|
| 111 |
]
|
| 112 |
|
| 113 |
+
ALLOWED_HOSTS = ['127.0.0.1','https://ferdinandpycode-lambda-hf.hf.space','http://localhost','192.168.100.28']
|
| 114 |
|
| 115 |
CORS_ALLOWED_ORIGINS = [
|
| 116 |
"http://localhost",
|
| 117 |
"https://ferdinandpycode-lambda-hf.hf.space",
|
| 118 |
"http://127.0.0.1",
|
| 119 |
+
"http://192.168.100.28"
|
| 120 |
]
|
| 121 |
|
| 122 |
|
utils/__pycache__/utils_function.cpython-310.pyc
CHANGED
|
Binary files a/utils/__pycache__/utils_function.cpython-310.pyc and b/utils/__pycache__/utils_function.cpython-310.pyc differ
|
|
|
utils/utils_function.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
from fairseq.models.transformer import TransformerModel
|
| 2 |
-
import os
|
| 3 |
import torch
|
| 4 |
-
import
|
| 5 |
-
import
|
|
|
|
| 6 |
|
| 7 |
class Translator:
|
| 8 |
def __init__(self, isFon:bool, device='cuda' if torch.cuda.is_available() else 'cpu'):
|
|
@@ -23,10 +23,33 @@ class Translator:
|
|
| 23 |
|
| 24 |
# Mettre le modèle en mode évaluation (pas de mise à jour des poids)
|
| 25 |
self.model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def translate(self, text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Encodage du texte en tokens
|
| 29 |
-
tokens = self.model.encode(
|
| 30 |
|
| 31 |
# Utilisation de la méthode generate avec le paramètre beam
|
| 32 |
translations = self.model.generate(tokens, beam=5)
|
|
@@ -37,4 +60,4 @@ class Translator:
|
|
| 37 |
# Décodage des tokens en traduction
|
| 38 |
translations = [self.model.decode(best_translation_tokens[i]) for i in range(5)]
|
| 39 |
|
| 40 |
-
return "\n".join(translations)
|
|
|
|
| 1 |
from fairseq.models.transformer import TransformerModel
|
|
|
|
| 2 |
import torch
|
| 3 |
+
import re
|
| 4 |
+
import string
|
| 5 |
+
|
| 6 |
|
| 7 |
class Translator:
|
| 8 |
def __init__(self, isFon:bool, device='cuda' if torch.cuda.is_available() else 'cpu'):
|
|
|
|
| 23 |
|
| 24 |
# Mettre le modèle en mode évaluation (pas de mise à jour des poids)
|
| 25 |
self.model.eval()
|
| 26 |
+
|
| 27 |
+
def preprocess(self, data):
|
| 28 |
+
print('Preprocessing...')
|
| 29 |
+
# Convertir chaque lettre en minuscule
|
| 30 |
+
text = data.lower().strip()
|
| 31 |
+
|
| 32 |
+
# Supprimer les apostrophes des phrases
|
| 33 |
+
text = re.sub("'", "", text)
|
| 34 |
+
|
| 35 |
+
# Supprimer toute ponctuation
|
| 36 |
+
exclude = set(string.punctuation)
|
| 37 |
+
text = ''.join(ch for ch in text if ch not in exclude)
|
| 38 |
+
|
| 39 |
+
# Supprimer les chiffres
|
| 40 |
+
digit = str.maketrans('', '', string.digits)
|
| 41 |
+
text = text.translate(digit)
|
| 42 |
+
|
| 43 |
+
return text
|
| 44 |
|
| 45 |
def translate(self, text):
|
| 46 |
+
|
| 47 |
+
print(text)
|
| 48 |
+
pre_traited = self.preprocess(text)
|
| 49 |
+
print(pre_traited)
|
| 50 |
+
|
| 51 |
# Encodage du texte en tokens
|
| 52 |
+
tokens = self.model.encode(pre_traited)
|
| 53 |
|
| 54 |
# Utilisation de la méthode generate avec le paramètre beam
|
| 55 |
translations = self.model.generate(tokens, beam=5)
|
|
|
|
| 60 |
# Décodage des tokens en traduction
|
| 61 |
translations = [self.model.decode(best_translation_tokens[i]) for i in range(5)]
|
| 62 |
|
| 63 |
+
return "\n".join(translations)
|