Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,11 @@ import gradio as gr
|
|
3 |
import json
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
# Load the translation pipeline
|
7 |
text_translator = pipeline(
|
8 |
-
"translation",
|
9 |
-
model="facebook/nllb-200-distilled-600M",
|
10 |
-
torch_dtype=torch.bfloat16
|
11 |
-
attn_implementation="eager"
|
12 |
)
|
13 |
|
14 |
# Load the JSON data for language codes
|
@@ -46,20 +45,20 @@ def translate_text(text, destination_language):
|
|
46 |
return f"Error: Could not find FLORES code for language {destination_language}"
|
47 |
|
48 |
try:
|
|
|
49 |
translation = text_translator(text, src_lang="eng_Latn", tgt_lang=dest_code)
|
50 |
return translation[0]["translation_text"]
|
51 |
except Exception as e:
|
52 |
return f"Error during translation: {str(e)}"
|
53 |
|
54 |
# Initialize the speech-to-text pipeline (Whisper model)
|
55 |
-
# Using the appropriate Whisper model for automatic speech recognition
|
56 |
speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
57 |
|
58 |
# Function to transcribe audio to text
|
59 |
def transcribe_audio(audio_file, destination_language):
|
60 |
try:
|
61 |
transcription_result = speech_to_text(audio_file)
|
62 |
-
print(f"Transcription result: {transcription_result}") #
|
63 |
if "text" in transcription_result:
|
64 |
transcription = transcription_result["text"]
|
65 |
else:
|
|
|
3 |
import json
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# Load the translation pipeline
|
7 |
text_translator = pipeline(
|
8 |
+
"translation",
|
9 |
+
model="facebook/nllb-200-distilled-600M",
|
10 |
+
torch_dtype=torch.bfloat16
|
|
|
11 |
)
|
12 |
|
13 |
# Load the JSON data for language codes
|
|
|
45 |
return f"Error: Could not find FLORES code for language {destination_language}"
|
46 |
|
47 |
try:
|
48 |
+
# Translation call
|
49 |
translation = text_translator(text, src_lang="eng_Latn", tgt_lang=dest_code)
|
50 |
return translation[0]["translation_text"]
|
51 |
except Exception as e:
|
52 |
return f"Error during translation: {str(e)}"
|
53 |
|
54 |
# Initialize the speech-to-text pipeline (Whisper model)
|
|
|
55 |
speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
56 |
|
57 |
# Function to transcribe audio to text
|
58 |
def transcribe_audio(audio_file, destination_language):
|
59 |
try:
|
60 |
transcription_result = speech_to_text(audio_file)
|
61 |
+
print(f"Transcription result: {transcription_result}") # Debugging output
|
62 |
if "text" in transcription_result:
|
63 |
transcription = transcription_result["text"]
|
64 |
else:
|