Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -50,26 +50,31 @@ def load_models():
|
|
50 |
return model_dict
|
51 |
|
52 |
def translation(source, target, text):
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
73 |
return result
|
74 |
|
75 |
|
@@ -77,8 +82,13 @@ def transcribe(inputs, task, source, target):
|
|
77 |
if inputs is None:
|
78 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
79 |
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
82 |
return text, translated_text
|
83 |
|
84 |
|
|
|
50 |
return model_dict
|
51 |
|
52 |
def translation(source, target, text):
|
53 |
+
try:
|
54 |
+
print("Début de la traduction")
|
55 |
+
if len(model_dict) == 2:
|
56 |
+
model_name = 'nllb-distilled-1.3B'
|
57 |
+
|
58 |
+
start_time = time.time()
|
59 |
+
source = flores_codes[source]
|
60 |
+
target = flores_codes[target]
|
61 |
+
|
62 |
+
model = model_dict[model_name + '_model']
|
63 |
+
tokenizer = model_dict[model_name + '_tokenizer']
|
64 |
+
|
65 |
+
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=source, tgt_lang=target)
|
66 |
+
output = translator(text, max_length=400)
|
67 |
+
|
68 |
+
end_time = time.time()
|
69 |
+
|
70 |
+
output = output[0]['translation_text']
|
71 |
+
result = {'inference_time': end_time - start_time,
|
72 |
+
'source': source,
|
73 |
+
'target': target,
|
74 |
+
'result': output}
|
75 |
+
print("Fin de la transcription")
|
76 |
+
except Exception as e:
|
77 |
+
print(f"Erreur lors de la transcription : {e}")
|
78 |
return result
|
79 |
|
80 |
|
|
|
82 |
if inputs is None:
|
83 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
84 |
|
85 |
+
try:
|
86 |
+
print("Début de la transcription")
|
87 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
88 |
+
translated_text = translation(source, target, text)
|
89 |
+
print("Fin de la transcription")
|
90 |
+
except Exception as e:
|
91 |
+
print(f"Erreur lors de la transcription : {e}")
|
92 |
return text, translated_text
|
93 |
|
94 |
|