seawolf2357 commited on
Commit
ca60e9b
·
verified ·
1 Parent(s): 77c47bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -20
app.py CHANGED
@@ -1,26 +1,22 @@
1
  import gradio as gr
 
 
 
2
 
3
- def latex_to_html(latex_str):
4
- # MathJax를 이용하여 LaTeX 수식을 HTML로 변환합니다.
5
- return f"""
6
- <!DOCTYPE html>
7
- <html>
8
- <body>
9
- <script src='https://polyfill.io/v3/polyfill.min.js?features=es6'></script>
10
- <script type="text/javascript" async
11
- src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML">
12
- </script>
13
- <p>
14
- $$ {latex_str} $$
15
- </p>
16
- </body>
17
- </html>
18
- """
19
 
20
- iface = gr.Interface(fn=latex_to_html,
21
  inputs="text",
22
- outputs="html",
23
- examples=[["E = mc^2"], ["\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}"]],
24
- title="LaTeX Renderer with MathJax")
25
 
26
  iface.launch(share=True)
 
1
  import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ import tempfile
4
+ import os
5
 
6
+ def latex_to_image(latex_str):
7
+ # LaTeX 문자열을 이미지로 변환
8
+ fig, ax = plt.subplots()
9
+ ax.text(0.5, 0.5, f'${latex_str}$', fontsize=15, ha='center', va='center')
10
+ ax.axis('off')
11
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmpfile:
12
+ plt.savefig(tmpfile.name, bbox_inches='tight', pad_inches=0.1)
13
+ plt.close(fig)
14
+ return tmpfile.name
 
 
 
 
 
 
 
15
 
16
+ iface = gr.Interface(fn=latex_to_image,
17
  inputs="text",
18
+ outputs="image",
19
+ title="LaTeX to Image Renderer",
20
+ description="Enter a LaTeX string to render it as an image.")
21
 
22
  iface.launch(share=True)