File size: 2,008 Bytes
8ac6e99
1
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_inputs"]}, {"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": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/blocks_inputs/lion.jpg"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "\n", "def combine(a, b):\n", "    return a + \" \" + b\n", "\n", "def mirror(x):\n", "    return x\n", "\n", "with gr.Blocks() as demo:\n", "\n", "    txt = gr.Textbox(label=\"Input\", lines=2)\n", "    txt_2 = gr.Textbox(label=\"Input 2\")\n", "    txt_3 = gr.Textbox(value=\"\", label=\"Output\")\n", "    btn = gr.Button(value=\"Submit\")\n", "    btn.click(combine, inputs=[txt, txt_2], outputs=[txt_3])\n", "\n", "    with gr.Row():\n", "        im = gr.Image()\n", "        im_2 = gr.Image()\n", "\n", "    btn = gr.Button(value=\"Mirror Image\")\n", "    btn.click(mirror, inputs=[im], outputs=[im_2])\n", "\n", "    gr.Markdown(\"## Text Examples\")\n", "    gr.Examples(\n", "        [[\"hi\", \"Adam\"], [\"hello\", \"Eve\"]],\n", "        [txt, txt_2],\n", "        txt_3,\n", "        combine,\n", "        cache_examples=True,\n", "    )\n", "    gr.Markdown(\"## Image Examples\")\n", "    gr.Examples(\n", "        examples=[os.path.join(os.path.abspath(''), \"lion.jpg\")],\n", "        inputs=im,\n", "        outputs=im_2,\n", "        fn=mirror,\n", "        cache_examples=True,\n", "    )\n", "\n", "if __name__ == \"__main__\":\n", "    demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}