seawolf2357 commited on
Commit
27983b3
ยท
verified ยท
1 Parent(s): da4f29b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -73,15 +73,27 @@ class MyClient(discord.Client):
73
  loop = asyncio.get_event_loop()
74
  response = await loop.run_in_executor(None, lambda: self.math_pipe([{"role": "user", "content": question}]))
75
  math_response = response[0]['generated_text']
76
-
77
  # QuickLaTeX API๋ฅผ ์ด์šฉํ•˜์—ฌ LaTeX ์ˆ˜์‹์„ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜
78
- encoded_formula = urllib.parse.quote_plus(math_response)
79
- quicklatex_url = f"https://quicklatex.com/latex3.f/png?formula={encoded_formula}"
80
- image_response = requests.get(quicklatex_url)
81
- image_url = image_response.text.split('\n')[1] # ์‘๋‹ต์—์„œ ์ด๋ฏธ์ง€ URL ์ถ”์ถœ
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  return math_response, image_url
84
-
85
  async def generate_response(self, message):
86
  global conversation_history
87
  user_input = message.content
 
73
  loop = asyncio.get_event_loop()
74
  response = await loop.run_in_executor(None, lambda: self.math_pipe([{"role": "user", "content": question}]))
75
  math_response = response[0]['generated_text']
76
+
77
  # QuickLaTeX API๋ฅผ ์ด์šฉํ•˜์—ฌ LaTeX ์ˆ˜์‹์„ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜
78
+ data = {
79
+ 'formula': math_response,
80
+ 'fsize': '17px',
81
+ 'fcolor': '000000',
82
+ 'mode': '0',
83
+ 'out': '1',
84
+ 'remhost': 'quicklatex.com'
85
+ }
86
+ headers = {'Content-Type': 'application/x-www-form-urlencoded'}
87
+ quicklatex_response = requests.post('https://quicklatex.com/latex3.f', data=data, headers=headers)
88
+ if quicklatex_response.status_code == 200:
89
+ # ์‘๋‹ต ํ…์ŠคํŠธ์—์„œ ์ฒซ ๋ฒˆ์งธ ์ค„์„ ๊ฐ€์ ธ์™€ URL์„ ์ถ”์ถœ
90
+ image_url = quicklatex_response.text.splitlines()[1]
91
+ else:
92
+ image_url = "Error generating image"
93
+ logging.error(f"QuickLaTeX error: {quicklatex_response.text}")
94
 
95
  return math_response, image_url
96
+
97
  async def generate_response(self, message):
98
  global conversation_history
99
  user_input = message.content