File size: 1,601 Bytes
0bd62e5
1
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: datetimes"]}, {"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", "with gr.Blocks() as demo:\n", "    date1 = gr.DateTime(include_time=True, label=\"Date and Time\", type=\"datetime\", elem_id=\"date1\")\n", "    date2 = gr.DateTime(include_time=False, label=\"Date Only\", type=\"string\", elem_id=\"date2\")\n", "    date3 = gr.DateTime(elem_id=\"date3\", timezone=\"Europe/Paris\")\n", "\n", "    with gr.Row():\n", "        btn1 = gr.Button(\"Load Date 1\")\n", "        btn2 = gr.Button(\"Load Date 2\")\n", "        btn3 = gr.Button(\"Load Date 3\")\n", "\n", "    click_output = gr.Textbox(label=\"Last Load\")\n", "    change_output = gr.Textbox(label=\"Last Change\")\n", "    submit_output = gr.Textbox(label=\"Last Submit\")\n", "\n", "    btn1.click(lambda x:x, date1, click_output)\n", "    btn2.click(lambda x:x, date2, click_output)\n", "    btn3.click(lambda x:x, date3, click_output)\n", "\n", "    for item in [date1, date2, date3]:\n", "        item.change(lambda x:x, item, change_output)\n", "        item.submit(lambda x:x, item, submit_output)\n", "\n", "if __name__ == \"__main__\":\n", "    demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}