Spaces:
Sleeping
Sleeping
File size: 1,733 Bytes
de0b50c | 1 | {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatinterface_deep_link"]}, {"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 time\n", "import gradio as gr\n", "\n", "def slow_echo(message, history):\n", " for i in range(len(message[\"text\"])):\n", " time.sleep(0.05)\n", " yield \"You typed: \" + message[\"text\"][: i + 1]\n", "\n", "chat = gr.ChatInterface(\n", " slow_echo,\n", " flagging_mode=\"manual\",\n", " flagging_options=[\"Like\", \"Spam\", \"Inappropriate\", \"Other\"],\n", " save_history=False,\n", " multimodal=True,\n", " api_name=\"chat\"\n", ")\n", "\n", "with gr.Blocks() as demo:\n", "\n", " chat.render()\n", " gr.DeepLinkButton()\n", "\n", "with demo.route(\"cached_examples\"):\n", " gr.Interface(lambda x, y: f\"{y}: {x}\",\n", " inputs=[gr.Textbox(label=\"name\"),\n", " gr.Radio(label=\"Salutation\", choices=[\"Hello\", \"Greetings\"])\n", " ],\n", " outputs=gr.Textbox(label=\"Output\"),\n", " examples=[[\"Freddy\", \"Hello\"]],\n", " cache_examples=True,\n", " api_name=\"predict\",\n", " deep_link=True)\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |