Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import gradio as gr
|
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
import speech_recognition as sr
|
| 7 |
-
from
|
| 8 |
import re
|
| 9 |
|
| 10 |
# --- 1. Configure API Key ---
|
|
@@ -17,7 +17,7 @@ except Exception as e:
|
|
| 17 |
print(f"Error configuring API key: {e}")
|
| 18 |
|
| 19 |
# --- 2. Initialize Translator ---
|
| 20 |
-
translator =
|
| 21 |
|
| 22 |
# --- 3. Define the System Prompt ---
|
| 23 |
SYSTEM_PROMPT = """
|
|
@@ -132,8 +132,9 @@ def translate_text(text, target_lang):
|
|
| 132 |
try:
|
| 133 |
if not text:
|
| 134 |
return ""
|
| 135 |
-
|
| 136 |
-
|
|
|
|
| 137 |
except Exception as e:
|
| 138 |
print(f"Translation error: {e}")
|
| 139 |
return text # Fallback to original text
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
import speech_recognition as sr
|
| 7 |
+
from deep_translator import GoogleTranslator
|
| 8 |
import re
|
| 9 |
|
| 10 |
# --- 1. Configure API Key ---
|
|
|
|
| 17 |
print(f"Error configuring API key: {e}")
|
| 18 |
|
| 19 |
# --- 2. Initialize Translator ---
|
| 20 |
+
translator = GoogleTranslator(source='auto', target='en')
|
| 21 |
|
| 22 |
# --- 3. Define the System Prompt ---
|
| 23 |
SYSTEM_PROMPT = """
|
|
|
|
| 132 |
try:
|
| 133 |
if not text:
|
| 134 |
return ""
|
| 135 |
+
translator = GoogleTranslator(source='auto', target=target_lang)
|
| 136 |
+
translation = translator.translate(text)
|
| 137 |
+
return translation
|
| 138 |
except Exception as e:
|
| 139 |
print(f"Translation error: {e}")
|
| 140 |
return text # Fallback to original text
|