gradio/demo/json_component/run.py
Yuichiro Tachibana (Tsuchiya) 937c858371
Use orjson to serialize dict including np.array (#8041)
* Use orjson to serialize dict including np.array

* add changeset

* Update json_component demo and add an E2E test using it

* Rename demo/json_component -> demo/json_component_blocks

* Add json_component_interface demo and an E2E test using it

* Fix to await assertion promises

* Revert renaming of json_component demo

* add changeset

* Rename js/app/test/json_component_blocks.spec.ts -> js/app/test/json_component.spec.ts

* Revert changes in routes.py and add orjson to json_component.py

* Update gr.Checkbox.postprocess to ensure a bool value is returned

* add changeset

* Remove the if-block in gr.Checkbox.postprocess handling NumPy arrays as they are not reasonable values to be interpreted as checkbox's value

* Update gr.JSON's docstring

* Add test/components/test_json_component.py

* Remove JSON component E2E tests

* Update gr.JSON's docstring

* docstring

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2024-04-25 16:13:01 +09:00

26 lines
626 B
Python

import gradio as gr
import numpy as np
with gr.Blocks() as demo:
inp = gr.JSON(
label="InputJSON",
value={
"Key 1": "Value 1",
"Key 2": {"Key 3": "Value 2", "Key 4": "Value 3"},
"Key 5": ["Item 1", "Item 2", "Item 3"],
"Key 6": 123,
"Key 7": 123.456,
"Key 8": True,
"Key 9": False,
"Key 10": None,
"Key 11": np.array([1, 2, 3]),
}
)
out = gr.JSON(label="OutputJSON")
btn = gr.Button("Submit")
btn.click(lambda x: x, inp, out)
if __name__ == "__main__":
demo.launch()