naonauno commited on
Commit
49d166b
·
verified ·
1 Parent(s): b219932

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -117,23 +117,15 @@ async def modify_accent(text: str, accent: str, enhance: bool = False) -> str:
117
 
118
  try:
119
  response = await model.generate_content_async(prompt)
120
- if not response or not response.candidates:
121
- logger.error("Empty response from Gemini AI")
 
122
  return text
123
 
124
- # Get the text content safely
125
- try:
126
- modified_text = response.text.strip()
127
- except AttributeError:
128
- try:
129
- modified_text = response.candidates[0].content.parts[0].text.strip()
130
- except (AttributeError, IndexError):
131
- logger.error("Could not extract text from Gemini AI response")
132
- return text
133
 
134
  # Clean up any remaining annotations or formatting
135
  modified_text = modified_text.replace('*', '').replace('(', '').replace(')', '')
136
- # Take only the first line if there are multiple lines
137
  modified_text = modified_text.split('\n')[0] if '\n' in modified_text else modified_text
138
 
139
  # If response is empty or contains unwanted formatting, return original
 
117
 
118
  try:
119
  response = await model.generate_content_async(prompt)
120
+ # Get content from the first part of the first candidate
121
+ parts = response.candidates[0].content.parts
122
+ if not parts:
123
  return text
124
 
125
+ modified_text = parts[0].text.strip()
 
 
 
 
 
 
 
 
126
 
127
  # Clean up any remaining annotations or formatting
128
  modified_text = modified_text.replace('*', '').replace('(', '').replace(')', '')
 
129
  modified_text = modified_text.split('\n')[0] if '\n' in modified_text else modified_text
130
 
131
  # If response is empty or contains unwanted formatting, return original