Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import torch
|
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 6 |
-
from
|
| 7 |
from gtts import gTTS
|
| 8 |
import librosa
|
| 9 |
import tempfile
|
|
@@ -19,9 +19,6 @@ class RealTimeTranslator:
|
|
| 19 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 20 |
self.model = self.model.to(self.device)
|
| 21 |
|
| 22 |
-
# Initialize translator
|
| 23 |
-
self.translator = Translator()
|
| 24 |
-
|
| 25 |
# Supported languages
|
| 26 |
self.languages = {
|
| 27 |
'en': 'English',
|
|
@@ -52,8 +49,8 @@ class RealTimeTranslator:
|
|
| 52 |
def translate_text(self, text, source_lang, target_lang):
|
| 53 |
"""Translate text using Google Translate"""
|
| 54 |
try:
|
| 55 |
-
translation =
|
| 56 |
-
return translation
|
| 57 |
except Exception as e:
|
| 58 |
return f"Error in translation: {str(e)}"
|
| 59 |
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 6 |
+
from deep_translator import GoogleTranslator # Replaced googletrans with deep-translator
|
| 7 |
from gtts import gTTS
|
| 8 |
import librosa
|
| 9 |
import tempfile
|
|
|
|
| 19 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 20 |
self.model = self.model.to(self.device)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
# Supported languages
|
| 23 |
self.languages = {
|
| 24 |
'en': 'English',
|
|
|
|
| 49 |
def translate_text(self, text, source_lang, target_lang):
|
| 50 |
"""Translate text using Google Translate"""
|
| 51 |
try:
|
| 52 |
+
translation = GoogleTranslator(source=source_lang, target=target_lang).translate(text)
|
| 53 |
+
return translation
|
| 54 |
except Exception as e:
|
| 55 |
return f"Error in translation: {str(e)}"
|
| 56 |
|