| 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() | |