Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
| 121 |
-
|
|
|
|
| 122 |
return text
|
| 123 |
|
| 124 |
-
|
| 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
|