seawolf2357 commited on
Commit
73b4995
ยท
verified ยท
1 Parent(s): 27249d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -1,22 +1,25 @@
1
- import requests
2
  import gradio as gr
3
 
4
  def render_latex_to_image(latex_str):
5
  """
6
- ์‚ฌ์šฉ์ž์˜ LaTeX ๋ฌธ์ž์—ด ์ž…๋ ฅ์„ ๋ฐ›์•„์„œ CodeCogs LaTeX API๋ฅผ ์ด์šฉํ•ด ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•˜๊ณ ,
7
  ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ URL์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
8
  """
9
- encoded_str = requests.utils.quote(latex_str) # URL์— ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋„๋ก LaTeX ๋ฌธ์ž์—ด ์ธ์ฝ”๋”ฉ
10
- # CodeCogs LaTeX ๋ Œ๋”๋ง ์„œ๋น„์Šค URL ์ƒ์„ฑ
11
- url = f"https://latex.codecogs.com/png.latex?{encoded_str}"
12
- return url # ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€์˜ URL์„ ๋ฐ˜ํ™˜
 
 
 
13
 
14
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
15
  iface = gr.Interface(
16
  fn=render_latex_to_image,
17
  inputs=gr.Textbox(placeholder="Enter LaTeX code here...", lines=4),
18
  outputs=gr.Image(),
19
- title="LaTeX to Image Renderer",
20
  description="Enter LaTeX code to render it into an image using the CodeCogs LaTeX Rendering API."
21
  )
22
 
 
1
+ import urllib.parse
2
  import gradio as gr
3
 
4
  def render_latex_to_image(latex_str):
5
  """
6
+ ์‚ฌ์šฉ์ž์˜ LaTeX ๋ฌธ์ž์—ด ์ž…๋ ฅ์„ ๋ฐ›์•„์„œ Codecogs LaTeX Rendering API๋ฅผ ์ด์šฉํ•ด ์ด๋ฏธ์ง€(png ํ˜•์‹)๋กœ ๋ณ€ํ™˜ํ•˜๊ณ ,
7
  ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ URL์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
8
  """
9
+ base_url = "https://latex.codecogs.com/png.latex?"
10
+ # LaTeX ๋ฌธ์ž์—ด์„ URL ์ธ์ฝ”๋”ฉ
11
+ encoded_str = urllib.parse.quote(latex_str)
12
+ # ์ตœ์ข… ์ด๋ฏธ์ง€ URL ์ƒ์„ฑ
13
+ image_url = f"{base_url}{encoded_str}"
14
+
15
+ return image_url
16
 
17
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
18
  iface = gr.Interface(
19
  fn=render_latex_to_image,
20
  inputs=gr.Textbox(placeholder="Enter LaTeX code here...", lines=4),
21
  outputs=gr.Image(),
22
+ title="LaTeX to Image Renderer with CodeCogs API",
23
  description="Enter LaTeX code to render it into an image using the CodeCogs LaTeX Rendering API."
24
  )
25