gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
32.14k stars 2.4k forks source link

Rendering latex on the web with gradio has serious bugs!!! #3373

Closed RedHeartSecretMan closed 1 year ago

RedHeartSecretMan commented 1 year ago

Describe the bug

Hello gradio developers:

I have noticed a serious bug with the gradio3.19.1 version I use. When I use the gradio.Markdown() component, any gradio.Markdown () that contains "$\sqrt{}$" in the string, even though I updated the matplotlib version, I hope you can improve as soon as possible

ValueError: 
\sqrt{}
     ^
ParseSyntaxException: Expected \sqrt{value}, found '{'  (at char 5), (line:1, col:6)

Is there an existing issue for this?

Reproduction

https://github.com/RedHeartSecretMan/PythonScript/blob/main/%E9%A1%B9%E7%9B%AE/OpenAIAPI/ChatGPT/WebChatGPT/Gradio/app.py

Screenshot

No response

Logs

UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
  fig = plt.figure(figsize=(0.01, 0.01))
2023-03-04 00:15:06.217 python[7118:137970] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
        0   CoreFoundation                      0x000000018ac543e8 __exceptionPreprocess + 176
        1   libobjc.A.dylib                     0x000000018a79eea8 objc_exception_throw + 60
        2   CoreFoundation                      0x000000018ac7d800 _CFBundleGetValueForInfoKey + 0
        3   AppKit                              0x000000018de8065c -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 320
        4   AppKit                              0x000000018de6e94c -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 816
        5   AppKit                              0x000000018de6e610 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
        6   _macosx.cpython-38-darwin.so        0x000000016b5e8964 -[Window initWithContentRect:styleMask:backing:defer:withManager:] + 68
        7   _macosx.cpython-38-darwin.so        0x000000016b5ebd68 FigureManager_init + 240
        8   python3.8                           0x0000000102fa77f0 wrap_init + 20
        9   python3.8                           0x0000000102f2e940 wrapperdescr_call + 212
        10  python3.8                           0x000000010303b20c _PyEval_EvalFrameDefault + 57000
        11  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        12  python3.8                           0x0000000102fa70f0 slot_tp_init + 324
        13  python3.8                           0x0000000102fac904 type_call + 272
        14  python3.8                           0x000000010304e6c8 call_function + 604
        15  python3.8                           0x0000000103034c70 _PyEval_EvalFrameDefault + 30988
        16  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        17  python3.8                           0x0000000102f27894 method_vectorcall + 120
        18  python3.8                           0x0000000103037340 _PyEval_EvalFrameDefault + 40924
        19  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        20  python3.8                           0x0000000102f27894 method_vectorcall + 120
        21  python3.8                           0x0000000103037340 _PyEval_EvalFrameDefault + 40924
        22  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        23  python3.8                           0x0000000102f27894 method_vectorcall + 120
        24  python3.8                           0x0000000103037340 _PyEval_EvalFrameDefault + 40924
        25  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        26  python3.8                           0x0000000102f2794c method_vectorcall + 304
        27  python3.8                           0x000000010303c0fc _PyEval_EvalFrameDefault + 60824
        28  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        29  python3.8                           0x000000010303c0fc _PyEval_EvalFrameDefault + 60824
        30  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        31  python3.8                           0x000000010303c0fc _PyEval_EvalFrameDefault + 60824
        32  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        33  python3.8                           0x000000010304e4f0 call_function + 132
        34  python3.8                           0x0000000103034ce8 _PyEval_EvalFrameDefault + 31108
        35  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        36  python3.8                           0x000000010304e4f0 call_function + 132
        37  python3.8                           0x0000000103034c70 _PyEval_EvalFrameDefault + 30988
        38  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        39  python3.8                           0x0000000102f27894 method_vectorcall + 120
        40  python3.8                           0x000000010304e4f0 call_function + 132
        41  python3.8                           0x0000000103034c70 _PyEval_EvalFrameDefault + 30988
        42  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        43  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        44  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        45  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        46  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        47  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        48  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        49  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        50  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        51  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        52  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        53  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        54  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        55  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        56  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        57  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        58  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        59  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        60  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        61  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        62  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        63  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        64  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        65  python3.8                           0x0000000103030ee4 _PyEval_EvalFrameDefault + 15232
        66  python3.8                           0x0000000102f3a3bc gen_send_ex + 184
        67  _asyncio.cpython-38-darwin.so       0x000000013c487bac task_step + 168
        68  _asyncio.cpython-38-darwin.so       0x000000013c4878dc TaskWakeupMethWrapper_call + 160
        69  python3.8                           0x0000000102f1e850 _PyObject_MakeTpCall + 328
        70  python3.8                           0x00000001030648bc context_run + 200
        71  python3.8                           0x0000000102f800ac cfunction_vectorcall_FASTCALL_KEYWORDS + 84
        72  python3.8                           0x0000000102f1f184 PyVectorcall_Call + 100
        73  python3.8                           0x000000010303fb78 _PyEval_EvalFrameDefault + 75796
        74  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        75  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        76  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        77  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        78  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        79  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        80  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        81  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        82  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        83  python3.8                           0x0000000103037340 _PyEval_EvalFrameDefault + 40924
        84  python3.8                           0x0000000102f20784 _PyFunction_Vectorcall + 1488
        85  python3.8                           0x0000000102f279bc method_vectorcall + 416
        86  python3.8                           0x0000000103037660 _PyEval_EvalFrameDefault + 41724
        87  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        88  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        89  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        90  python3.8                           0x00000001030351dc _PyEval_EvalFrameDefault + 32376
        91  python3.8                           0x0000000102f20354 _PyFunction_Vectorcall + 416
        92  python3.8                           0x0000000102f279bc method_vectorcall + 416
        93  python3.8                           0x0000000102f1f668 PyObject_Call + 108
        94  python3.8                           0x00000001031071bc t_bootstrap + 188
        95  python3.8                           0x00000001030a5c8c pythread_wrapper + 48
        96  libsystem_pthread.dylib             0x000000018aafa06c _pthread_start + 148
        97  libsystem_pthread.dylib             0x000000018aaf4e2c thread_start + 8
)
libc++abi: terminating with uncaught exception of type NSException

System Info

macOS 13.2.1
python 3.8.16
gradio 3.19.1
matplotlib 3.7.0

Severity

blocking all usage of gradio

abidlabs commented 1 year ago

Hi @RedHeartSecretMan it looks like this particular issue (rendering a "sqrt{}" with nothing inside) is an edge case that is missed by matplotlib's LaTeX rendering engine. This can be confirmed by trying to use LaTeX with some matplotlib code:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

ax.bar(fruits, counts, label=bar_labels, color=bar_colors)

ax.set_ylabel('Test: $\sqrt{}$')

plt.show()

which is what Gradio uses to render the LaTeX. I would suggest opening an issue here so that all users of matplotlib can benefit: https://github.com/matplotlib/matplotlib/issues

RedHeartSecretMan commented 1 year ago

thanks!