File size: 2,048 Bytes
a03b3ba
1
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_js_load"]}, {"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 welcome(name):\n", "    return f\"Welcome to Gradio, {name}!\"\n", "\n", "js = \"\"\"\n", "function createGradioAnimation() {\n", "    var container = document.createElement('div');\n", "    container.id = 'gradio-animation';\n", "    container.style.fontSize = '2em';\n", "    container.style.fontWeight = 'bold';\n", "    container.style.textAlign = 'center';\n", "    container.style.marginBottom = '20px';\n", "\n", "    var text = 'Welcome to Gradio!';\n", "    for (var i = 0; i < text.length; i++) {\n", "        (function(i){\n", "            setTimeout(function(){\n", "                var letter = document.createElement('span');\n", "                letter.style.opacity = '0';\n", "                letter.style.transition = 'opacity 0.5s';\n", "                letter.innerText = text[i];\n", "\n", "                container.appendChild(letter);\n", "\n", "                setTimeout(function() {\n", "                    letter.style.opacity = '1';\n", "                }, 50);\n", "            }, i * 250);\n", "        })(i);\n", "    }\n", "\n", "    var gradioContainer = document.querySelector('.gradio-container');\n", "    gradioContainer.insertBefore(container, gradioContainer.firstChild);\n", "\n", "    return 'Animation created';\n", "}\n", "\"\"\"\n", "with gr.Blocks(js=js) as demo:\n", "    inp = gr.Textbox(placeholder=\"What is your name?\")\n", "    out = gr.Textbox()\n", "    inp.change(welcome, inp, out)\n", "\n", "if __name__ == \"__main__\":\n", "    demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}