Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Commit
โข
cf85588
1
Parent(s):
669bbdf
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):
|