{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_simple_squares"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "demo = gr.Blocks(css=\"\"\"#btn {color: red} .abc {font-family: \"Comic Sans MS\", \"Comic Sans\", cursive !important}\"\"\")\n", "\n", "with demo:\n", " default_json = {\"a\": \"a\"}\n", "\n", " num = gr.State(value=0)\n", " squared = gr.Number(value=0)\n", " btn = gr.Button(\"Next Square\", elem_id=\"btn\", elem_classes=[\"abc\", \"def\"])\n", "\n", " stats = gr.State(value=default_json)\n", " table = gr.JSON()\n", "\n", " def increase(var, stats_history):\n", " var += 1\n", " stats_history[str(var)] = var**2\n", " return var, var**2, stats_history, stats_history\n", "\n", " btn.click(increase, [num, stats], [num, squared, stats, table])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}