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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -1,13 +1,26 @@
1
  import gradio as gr
2
 
3
- def render_latex(latex_code):
4
- return latex_code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(
7
- fn=render_latex,
8
- inputs=gr.TextArea(placeholder="Enter LaTeX code here...", value="E = mc^2"), outputs="text",
9
- title="LaTeX Code Renderer",
10
- description="This interface returns LaTeX code as is. Please use a LaTeX renderer in your browser to see the formatted output."
11
- )
12
 
13
- iface.launch()
 
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)