File size: 5,142 Bytes
0ad74ed
1
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_outputs"]}, {"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", "def make_markdown():\n", "    return [\n", "        [\n", "            \"# hello again\",\n", "            \"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.\",\n", "            '<img src=\"https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80\"/>',\n", "        ],\n", "        [\n", "            \"## hello again again\",\n", "            \"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.\",\n", "            '<img src=\"https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80\"/>',\n", "        ],\n", "        [\n", "            \"### hello thrice\",\n", "            \"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.\",\n", "            '<img src=\"https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80\"/>',\n", "        ],\n", "    ]\n", "\n", "with gr.Blocks() as demo:\n", "    with gr.Column():\n", "        txt = gr.Textbox(label=\"Small Textbox\", lines=1, show_label=False)\n", "        txt = gr.Textbox(label=\"Large Textbox\", lines=5, show_label=False)\n", "        num = gr.Number(label=\"Number\", show_label=False)\n", "        check = gr.Checkbox(label=\"Checkbox\", show_label=False)\n", "        check_g = gr.CheckboxGroup(\n", "            label=\"Checkbox Group\", choices=[\"One\", \"Two\", \"Three\"], show_label=False\n", "        )\n", "        radio = gr.Radio(\n", "            label=\"Radio\", choices=[\"One\", \"Two\", \"Three\"], show_label=False\n", "        )\n", "        drop = gr.Dropdown(\n", "            label=\"Dropdown\", choices=[\"One\", \"Two\", \"Three\"], show_label=False\n", "        )\n", "        slider = gr.Slider(label=\"Slider\", show_label=False)\n", "        audio = gr.Audio(show_label=False)\n", "        file = gr.File(show_label=False)\n", "        video = gr.Video(show_label=False)\n", "        image = gr.Image(show_label=False)\n", "        df = gr.Dataframe(show_label=False)\n", "        html = gr.HTML(show_label=False)\n", "        json = gr.JSON(show_label=False)\n", "        md = gr.Markdown(show_label=False)\n", "        label = gr.Label(show_label=False)\n", "        highlight = gr.HighlightedText(show_label=False)\n", "        gr.Dataframe(interactive=True, col_count=(3, \"fixed\"), label=\"Dataframe\")\n", "        gr.Dataframe(interactive=True, col_count=4, label=\"Dataframe\")\n", "        gr.Dataframe(\n", "            interactive=True, headers=[\"One\", \"Two\", \"Three\", \"Four\"], label=\"Dataframe\"\n", "        )\n", "        gr.Dataframe(\n", "            interactive=True,\n", "            headers=[\"One\", \"Two\", \"Three\", \"Four\"],\n", "            col_count=(4, \"fixed\"),\n", "            row_count=(7, \"fixed\"),\n", "            value=[[0, 0, 0, 0]],\n", "            label=\"Dataframe\",\n", "        )\n", "        gr.Dataframe(\n", "            interactive=True, headers=[\"One\", \"Two\", \"Three\", \"Four\"], col_count=4\n", "        )\n", "        df = gr.DataFrame(\n", "            [\n", "                [\n", "                    \"# hello\",\n", "                    \"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.\",\n", "                    '<img src=\"https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80\"/>',\n", "                ],\n", "                [\n", "                    \"## hello\",\n", "                    \"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.\",\n", "                    '<img src=\"https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80\"/>',\n", "                ],\n", "                [\n", "                    \"### hello\",\n", "                    \"Hello my name is frank, I am liking the small turtle you have there. It would be a shame if it went missing.\",\n", "                    '<img src=\"https://images.unsplash.com/photo-1574613362884-f79513a5128c?fit=crop&w=500&q=80\"/>',\n", "                ],\n", "            ],\n", "            headers=[\"One\", \"Two\", \"Three\"],\n", "            wrap=True,\n", "            datatype=[\"markdown\", \"markdown\", \"html\"],\n", "            interactive=True,\n", "        )\n", "        btn = gr.Button(\"Run\")\n", "        btn.click(fn=make_markdown, inputs=None, outputs=df)\n", "\n", "if __name__ == \"__main__\":\n", "    demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}