File size: 1,843 Bytes
0bd62e5 |
1 |
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: queue_full_e2e_test"]}, {"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", "import time\n", "import random\n", "\n", "n_calls = 0\n", "\n", "def get_random_number():\n", " global n_calls\n", " if n_calls == 1:\n", " n_calls += 1\n", " raise gr.Error(\"This is a gradio error\")\n", " n_calls += 1\n", " time.sleep(5)\n", " return random.randrange(1, 10)\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " first = gr.Button(\"First Call\")\n", " second = gr.Button(\"Second Call\")\n", " third = gr.Button(\"Third Call\")\n", " fourth = gr.Button(\"Fourth Call\")\n", " with gr.Column():\n", " first_o = gr.Number(label=\"First Result\")\n", " second_o = gr.Number(label=\"Second Result\")\n", " third_o = gr.Number(label=\"Third Result\")\n", " fourth_o = gr.Number(label=\"Fourth Result\")\n", "\n", " first.click(get_random_number, None, first_o, concurrency_id=\"f\")\n", " second.click(get_random_number, None, second_o, concurrency_id=\"f\")\n", " third.click(get_random_number, None, third_o, concurrency_id=\"f\")\n", " fourth.click(get_random_number, None, fourth_o, concurrency_id=\"f\")\n", "\n", "demo.queue(max_size=2)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |