File size: 2,393 Bytes
0ad74ed
1
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_chained_events"]}, {"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 failure():\n", "    raise gr.Error(\"This should fail!\")\n", "\n", "def exception():\n", "    raise ValueError(\"Something went wrong\")\n", "\n", "def success():\n", "    return True\n", "\n", "def warning_fn():\n", "    gr.Warning(\"This is a warning!\")\n", "\n", "def info_fn():\n", "    gr.Info(\"This is some info\")\n", "\n", "with gr.Blocks() as demo:\n", "    gr.Markdown(\"Used in E2E tests of success event trigger. The then event covered in chatbot E2E tests.\"\n", "                \" Also testing that the status modals show up.\")\n", "    with gr.Row():\n", "        result = gr.Textbox(label=\"Result\")\n", "        result_2 = gr.Textbox(label=\"Consecutive Event\")\n", "    with gr.Row():\n", "        success_btn = gr.Button(value=\"Trigger Success\")\n", "        success_btn_2 = gr.Button(value=\"Trigger Consecutive Success\")\n", "        failure_btn = gr.Button(value=\"Trigger Failure\")\n", "        failure_exception = gr.Button(value=\"Trigger Failure With ValueError\")\n", "    with gr.Row():\n", "        trigger_warning = gr.Button(value=\"Trigger Warning\")\n", "        trigger_info = gr.Button(value=\"Trigger Info\")\n", "\n", "        success_btn_2.click(success, None, None).success(lambda: \"First Event Trigered\", None, result).success(lambda: \"Consecutive Event Triggered\", None, result_2)\n", "        success_btn.click(success, None, None).success(lambda: \"Success event triggered\", inputs=None, outputs=result)\n", "        failure_btn.click(failure, None, None).success(lambda: \"Should not be triggered\", inputs=None, outputs=result)\n", "        failure_exception.click(exception, None, None)\n", "        trigger_warning.click(warning_fn, None, None)\n", "        trigger_info.click(info_fn, None, None)\n", "\n", "if __name__ == \"__main__\":\n", "    demo.launch(show_error=True)\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}