Himel09 commited on
Commit
4fdb203
·
verified ·
1 Parent(s): 2c9e41d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
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
- translated = response_translation.candidates[0].content.strip()
 
 
 
 
 
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: