Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,29 @@ from langdetect import detect
|
|
| 3 |
from gtts import gTTS
|
| 4 |
import os
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def identify_and_pronounce(name, selected_lang):
|
| 7 |
if not name or name.strip() == "":
|
| 8 |
return "Please enter a name.", None
|
|
@@ -12,29 +35,6 @@ def identify_and_pronounce(name, selected_lang):
|
|
| 12 |
detected_lang = detect(name)
|
| 13 |
except Exception as e:
|
| 14 |
return f"Error detecting language: {str(e)}", None
|
| 15 |
-
|
| 16 |
-
# Map detected language code to a human-readable name and gTTS-compatible code
|
| 17 |
-
lang_map = {
|
| 18 |
-
'en': 'English',
|
| 19 |
-
'es': 'Spanish',
|
| 20 |
-
'fr': 'French',
|
| 21 |
-
'de': 'German',
|
| 22 |
-
'it': 'Italian',
|
| 23 |
-
'pt': 'Portuguese',
|
| 24 |
-
'nl': 'Dutch',
|
| 25 |
-
'ru': 'Russian',
|
| 26 |
-
'zh-cn': 'Chinese (Simplified)',
|
| 27 |
-
'ja': 'Japanese',
|
| 28 |
-
'ko': 'Korean',
|
| 29 |
-
'pl': 'Polish',
|
| 30 |
-
'uk': 'Ukrainian',
|
| 31 |
-
'sk': 'Slovak',
|
| 32 |
-
'lt': 'Lithuanian',
|
| 33 |
-
'cs': 'Czech',
|
| 34 |
-
'sr': 'Serbian',
|
| 35 |
-
'hr': 'Croatian',
|
| 36 |
-
'hi': 'Hindi'
|
| 37 |
-
}
|
| 38 |
|
| 39 |
# If detected language isn't in map, use English as default but allow override
|
| 40 |
detected_lang_name = lang_map.get(detected_lang, 'English (default)')
|
|
@@ -62,7 +62,7 @@ language_options = ["Auto"] + list(lang_map.values()) # Include "Auto" as defau
|
|
| 62 |
interface = gr.Interface(
|
| 63 |
fn=identify_and_pronounce,
|
| 64 |
inputs=[
|
| 65 |
-
gr.Textbox(label="Enter a name", value="Tomasz Durzyński"),
|
| 66 |
gr.Dropdown(choices=language_options, label="Select Language (Auto uses detection)", value="Auto")
|
| 67 |
],
|
| 68 |
outputs=[
|
|
|
|
| 3 |
from gtts import gTTS
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Define lang_map in global scope
|
| 7 |
+
lang_map = {
|
| 8 |
+
'en': 'English',
|
| 9 |
+
'es': 'Spanish',
|
| 10 |
+
'fr': 'French',
|
| 11 |
+
'de': 'German',
|
| 12 |
+
'it': 'Italian',
|
| 13 |
+
'pt': 'Portuguese',
|
| 14 |
+
'nl': 'Dutch',
|
| 15 |
+
'ru': 'Russian',
|
| 16 |
+
'zh-cn': 'Chinese (Simplified)',
|
| 17 |
+
'ja': 'Japanese',
|
| 18 |
+
'ko': 'Korean',
|
| 19 |
+
'pl': 'Polish',
|
| 20 |
+
'uk': 'Ukrainian',
|
| 21 |
+
'sk': 'Slovak',
|
| 22 |
+
'lt': 'Lithuanian',
|
| 23 |
+
'cs': 'Czech',
|
| 24 |
+
'sr': 'Serbian',
|
| 25 |
+
'hr': 'Croatian',
|
| 26 |
+
'hi': 'Hindi'
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
def identify_and_pronounce(name, selected_lang):
|
| 30 |
if not name or name.strip() == "":
|
| 31 |
return "Please enter a name.", None
|
|
|
|
| 35 |
detected_lang = detect(name)
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error detecting language: {str(e)}", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# If detected language isn't in map, use English as default but allow override
|
| 40 |
detected_lang_name = lang_map.get(detected_lang, 'English (default)')
|
|
|
|
| 62 |
interface = gr.Interface(
|
| 63 |
fn=identify_and_pronounce,
|
| 64 |
inputs=[
|
| 65 |
+
gr.Textbox(label="Enter a name", value="Tomasz Durzyński"),
|
| 66 |
gr.Dropdown(choices=language_options, label="Select Language (Auto uses detection)", value="Auto")
|
| 67 |
],
|
| 68 |
outputs=[
|