File size: 2,277 Bytes
77049ff
1
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_joined"]}, {"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", "os.mkdir('files')\n", "!wget -q -O files/cheetah1.jpg https://github.com/gradio-app/gradio/raw/main/demo/blocks_joined/files/cheetah1.jpg"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["from time import sleep\n", "import gradio as gr\n", "import os\n", "\n", "cheetah = os.path.join(os.path.abspath(''), \"files/cheetah1.jpg\")\n", "\n", "def img(text):\n", "    sleep(3)\n", "    return [\n", "        cheetah,\n", "        cheetah,\n", "        cheetah,\n", "        cheetah,\n", "        cheetah,\n", "        cheetah,\n", "        cheetah,\n", "        cheetah,\n", "        cheetah,\n", "    ]\n", "\n", "with gr.Blocks(css=\".container { max-width: 800px; margin: auto; }\") as demo:\n", "    gr.Markdown(\"<h1><center>DALL\u00b7E mini</center></h1>\")\n", "    gr.Markdown(\n", "        \"DALL\u00b7E mini is an AI model that generates images from any prompt you give!\"\n", "    )\n", "    with gr.Group():\n", "        with gr.Row(equal_height=True):\n", "            text = gr.Textbox(\n", "                label=\"Enter your prompt\",\n", "                max_lines=1,\n", "                container=False,\n", "            )\n", "            btn = gr.Button(\"Run\", scale=0)\n", "        gallery = gr.Gallery(\n", "            label=\"Generated images\",\n", "            show_label=False,\n", "            columns=(1, 3),\n", "            height=\"auto\",\n", "        )\n", "    btn.click(img, inputs=text, outputs=gallery)\n", "\n", "if __name__ == \"__main__\":\n", "    demo.launch()\n", "\n", "# margin = (TOP, RIGHT, BOTTOM, LEFT)\n", "# rounded = (TOPLEFT, TOPRIGHT, BOTTOMRIGHT, BOTTOMLEFT)\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}