aliabd HF staff commited on
Commit
1502ca2
1 Parent(s): dbc2622

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +8 -8
  2. run.ipynb +1 -0
  3. run.py +42 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Todo List
3
- emoji: 🐢
4
- colorFrom: pink
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 4.32.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: todo_list
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 4.32.1
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: todo_list"]}, {"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", " \n", " tasks = gr.State([])\n", " new_task = gr.Textbox(label=\"Task Name\", autofocus=True)\n", "\n", " def add_task(tasks, new_task_name):\n", " return tasks + [{\"name\": new_task_name, \"complete\": False}], \"\"\n", "\n", " new_task.submit(add_task, [tasks, new_task], [tasks, new_task])\n", "\n", " @gr.render(inputs=tasks)\n", " def render_todos(task_list):\n", " complete = [task for task in task_list if task[\"complete\"]]\n", " incomplete = [task for task in task_list if not task[\"complete\"]]\n", " gr.Markdown(f\"### Incomplete Tasks ({len(incomplete)})\")\n", " for task in incomplete:\n", " with gr.Row():\n", " gr.Textbox(task['name'], show_label=False, container=False)\n", " done_btn = gr.Button(\"Done\", scale=0)\n", " def mark_done(task=task):\n", " _task_list = task_list[:]\n", " _task_list[task_list.index(task)] = {\"name\": task[\"name\"], \"complete\": True}\n", " return _task_list\n", " done_btn.click(mark_done, None, [tasks])\n", "\n", " delete_btn = gr.Button(\"Delete\", scale=0, variant=\"stop\")\n", " def delete(task=task):\n", " task_index = task_list.index(task)\n", " return task_list[:task_index] + task_list[task_index+1:]\n", " delete_btn.click(delete, None, [tasks])\n", "\n", " gr.Markdown(f\"### Complete Tasks ({len(complete)})\")\n", " for task in complete:\n", " gr.Textbox(task['name'], show_label=False, container=False)\n", "\n", "\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ with gr.Blocks() as demo:
4
+
5
+ tasks = gr.State([])
6
+ new_task = gr.Textbox(label="Task Name", autofocus=True)
7
+
8
+ def add_task(tasks, new_task_name):
9
+ return tasks + [{"name": new_task_name, "complete": False}], ""
10
+
11
+ new_task.submit(add_task, [tasks, new_task], [tasks, new_task])
12
+
13
+ @gr.render(inputs=tasks)
14
+ def render_todos(task_list):
15
+ complete = [task for task in task_list if task["complete"]]
16
+ incomplete = [task for task in task_list if not task["complete"]]
17
+ gr.Markdown(f"### Incomplete Tasks ({len(incomplete)})")
18
+ for task in incomplete:
19
+ with gr.Row():
20
+ gr.Textbox(task['name'], show_label=False, container=False)
21
+ done_btn = gr.Button("Done", scale=0)
22
+ def mark_done(task=task):
23
+ _task_list = task_list[:]
24
+ _task_list[task_list.index(task)] = {"name": task["name"], "complete": True}
25
+ return _task_list
26
+ done_btn.click(mark_done, None, [tasks])
27
+
28
+ delete_btn = gr.Button("Delete", scale=0, variant="stop")
29
+ def delete(task=task):
30
+ task_index = task_list.index(task)
31
+ return task_list[:task_index] + task_list[task_index+1:]
32
+ delete_btn.click(delete, None, [tasks])
33
+
34
+ gr.Markdown(f"### Complete Tasks ({len(complete)})")
35
+ for task in complete:
36
+ gr.Textbox(task['name'], show_label=False, container=False)
37
+
38
+
39
+
40
+
41
+ if __name__ == "__main__":
42
+ demo.launch()