Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,6 @@ def translation_to_French(api_key, text):
|
|
| 14 |
return "Error: Input Text is empty", None
|
| 15 |
|
| 16 |
try:
|
| 17 |
-
|
| 18 |
genai.configure(api_key=api_key)
|
| 19 |
model = genai.GenerativeModel("gemini-2.5-flash")
|
| 20 |
|
|
@@ -27,7 +26,12 @@ def translation_to_French(api_key, text):
|
|
| 27 |
max_output_tokens=150
|
| 28 |
)
|
| 29 |
)
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Pronunciation prompt
|
| 33 |
pronunciation_prompt = (
|
|
@@ -43,7 +47,12 @@ def translation_to_French(api_key, text):
|
|
| 43 |
max_output_tokens=150
|
| 44 |
)
|
| 45 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
pronunciation = response_pronunciation.candidates[0].content.strip()
|
|
|
|
| 47 |
return translated, pronunciation
|
| 48 |
|
| 49 |
except Exception as e:
|
|
|
|
| 14 |
return "Error: Input Text is empty", None
|
| 15 |
|
| 16 |
try:
|
|
|
|
| 17 |
genai.configure(api_key=api_key)
|
| 18 |
model = genai.GenerativeModel("gemini-2.5-flash")
|
| 19 |
|
|
|
|
| 26 |
max_output_tokens=150
|
| 27 |
)
|
| 28 |
)
|
| 29 |
+
|
| 30 |
+
# ✅ Check if candidates exist
|
| 31 |
+
if not response_translation or not response_translation.candidates:
|
| 32 |
+
return "Error: No translation returned from Gemini API.", None
|
| 33 |
+
|
| 34 |
+
translated = response_translation.candidates[0].content.strip()
|
| 35 |
|
| 36 |
# Pronunciation prompt
|
| 37 |
pronunciation_prompt = (
|
|
|
|
| 47 |
max_output_tokens=150
|
| 48 |
)
|
| 49 |
)
|
| 50 |
+
|
| 51 |
+
if not response_pronunciation or not response_pronunciation.candidates:
|
| 52 |
+
return translated, "Error: No pronunciation returned from Gemini API."
|
| 53 |
+
|
| 54 |
pronunciation = response_pronunciation.candidates[0].content.strip()
|
| 55 |
+
|
| 56 |
return translated, pronunciation
|
| 57 |
|
| 58 |
except Exception as e:
|