File size: 1,350 Bytes
0bd62e5 |
1 |
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: upload_and_download"]}, {"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": ["from pathlib import Path\n", "import gradio as gr\n", "\n", "def upload_file(filepath):\n", " name = Path(filepath).name\n", " return [gr.UploadButton(visible=False), gr.DownloadButton(label=f\"Download {name}\", value=filepath, visible=True)]\n", "\n", "def download_file():\n", " return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"First upload a file and and then you'll be able download it (but only once!)\")\n", " with gr.Row():\n", " u = gr.UploadButton(\"Upload a file\", file_count=\"single\")\n", " d = gr.DownloadButton(\"Download the file\", visible=False)\n", "\n", " u.upload(upload_file, u, [u, d])\n", " d.click(download_file, None, [u, d])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |