Download app.py from multimodalart/gr-number-negative-cache-bug: direct link, hf CLI and curl.
- Browser
- Download file 641 Bytes
-
https://huggingface.co/spaces/multimodalart/gr-number-negative-cache-bug/resolve/main/app.py
- Command line
-
hf download hf://spaces/multimodalart/gr-number-negative-cache-bug/app.py
-
curl -L -o app.py https://huggingface.co/spaces/multimodalart/gr-number-negative-cache-bug/resolve/main/app.py
641 Bytes
| import gradio as gr | |
| # Minimal repro: a `gr.Number` output cached via `gr.Examples` with a NEGATIVE value. | |
| # Click the example below -> json.decoder.JSONDecodeError in Number.read_from_flag. | |
| # Cause: sanitize_value_for_csv prepends a "'" to the "-0.5678" string in log.csv, | |
| # so read_from_flag does json.loads("'-0.5678") on read-back and crashes. | |
| # Flip the fn to return a positive number (e.g. 0.5678) and it works fine. | |
| demo = gr.Interface( | |
| fn=lambda x: -0.5678, # any negative number | |
| inputs=gr.Textbox(), | |
| outputs=gr.Number(), | |
| examples=[["hi"]], | |
| cache_examples=True, | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |