Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -157,27 +157,28 @@ class MyClient(discord.Client):
|
|
| 157 |
return f"{user_mention}, {full_response}"
|
| 158 |
|
| 159 |
async def send_message_with_latex(self, channel, message):
|
| 160 |
-
|
| 161 |
# 텍스트와 LaTeX 수식 분리
|
| 162 |
-
|
| 163 |
|
| 164 |
# 텍스트 먼저 출력
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
|
| 170 |
# LaTeX 수식 처리 및 이미지로 출력
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
-
except Exception as e:
|
| 179 |
-
logging.error(f"Error in send_message_with_latex: {str(e)}")
|
| 180 |
-
await channel.send("An error occurred while processing the message.")
|
| 181 |
|
| 182 |
|
| 183 |
async def send_long_message(self, channel, message):
|
|
|
|
| 157 |
return f"{user_mention}, {full_response}"
|
| 158 |
|
| 159 |
async def send_message_with_latex(self, channel, message):
|
| 160 |
+
try:
|
| 161 |
# 텍스트와 LaTeX 수식 분리
|
| 162 |
+
text_parts = re.split(r'(\$\$.*?\$\$|\$.*?\$)', message, flags=re.DOTALL)
|
| 163 |
|
| 164 |
# 텍스트 먼저 출력
|
| 165 |
+
for part in text_parts:
|
| 166 |
+
if not part.startswith('$'):
|
| 167 |
+
if part.strip():
|
| 168 |
+
await self.send_long_message(channel, part.strip())
|
| 169 |
|
| 170 |
# LaTeX 수식 처리 및 이미지로 출력
|
| 171 |
+
for part in text_parts:
|
| 172 |
+
if part.startswith('$'):
|
| 173 |
+
latex_content = part.strip('$')
|
| 174 |
+
image_base64 = latex_to_image(latex_content)
|
| 175 |
+
image_binary = base64.b64decode(image_base64)
|
| 176 |
+
await channel.send(file=discord.File(BytesIO(image_binary), 'equation.png'))
|
| 177 |
+
|
| 178 |
+
except Exception as e:
|
| 179 |
+
logging.error(f"Error in send_message_with_latex: {str(e)}")
|
| 180 |
+
await channel.send("An error occurred while processing the message.")
|
| 181 |
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
|
| 184 |
async def send_long_message(self, channel, message):
|