Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Progress Bar component #2750

Merged
merged 80 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
66c9b85
changes
aliabid94 Dec 1, 2022
fd97d93
version
abidlabs Dec 1, 2022
b475014
Merge branch 'main' into progress
abidlabs Dec 1, 2022
b52f921
changes
aliabid94 Dec 13, 2022
7ffcf79
changes
aliabid94 Dec 15, 2022
4e29cf7
fixes
aliabid94 Dec 16, 2022
1bc7788
changes
aliabid94 Dec 20, 2022
9c1ee0d
Merge remote-tracking branch 'origin' into progress
aliabid94 Dec 20, 2022
0f630b8
changes
aliabid94 Dec 20, 2022
10211c3
Merge remote-tracking branch 'origin' into progress
aliabid94 Dec 20, 2022
451050e
changes
aliabid94 Dec 21, 2022
2672e24
changes
aliabid94 Dec 21, 2022
316606f
chagnes
aliabid94 Dec 21, 2022
cec8100
Merge remote-tracking branch 'origin' into progress
aliabid94 Dec 21, 2022
799eeeb
chagnes
aliabid94 Dec 21, 2022
356bb3d
fix
aliabid94 Dec 21, 2022
fd65378
changes
aliabid94 Dec 21, 2022
0dd7a07
changes
aliabid94 Dec 21, 2022
7498c9b
changes
aliabid94 Dec 21, 2022
e6cd154
change
aliabid94 Dec 21, 2022
adc4ba3
changes
aliabid94 Dec 21, 2022
141f1a8
Merge remote-tracking branch 'origin' into progress
aliabid94 Dec 21, 2022
0ee8240
changes
aliabid94 Dec 21, 2022
4d1511e
changes
aliabid94 Dec 21, 2022
684e052
changes
aliabid94 Dec 21, 2022
dd0b78f
changes
aliabid94 Dec 21, 2022
7098773
changes
aliabid94 Dec 21, 2022
763c074
changes
aliabid94 Dec 21, 2022
0a9b830
changes
aliabid94 Dec 21, 2022
1885eb7
changes
aliabid94 Dec 21, 2022
7dc58d5
changes
aliabid94 Dec 21, 2022
7483d96
changes
aliabid94 Dec 21, 2022
96cc934
changes
aliabid94 Dec 21, 2022
d5195be
version update
aliabid94 Dec 21, 2022
f98b799
Commit from GitHub Actions (Upload Python Package)
aliabid94 Dec 21, 2022
0675d7f
merge change
aliabid94 Dec 21, 2022
84d2e57
changes
aliabid94 Dec 21, 2022
ecb871b
changes
aliabid94 Dec 21, 2022
97179af
changes
aliabid94 Dec 21, 2022
053c368
changes
aliabid94 Dec 21, 2022
e19fb20
fix
aliabid94 Dec 21, 2022
234cb72
Merge remote-tracking branch 'origin' into progress
aliabid94 Dec 21, 2022
1331d4f
changes
aliabid94 Dec 21, 2022
3411b15
changes
aliabid94 Dec 21, 2022
510bccc
changes
aliabid94 Dec 21, 2022
3b0b238
Update CHANGELOG.md
aliabid94 Dec 21, 2022
6f5bc0f
Update CHANGELOG.md
aliabid94 Dec 21, 2022
f0c22dc
Update CHANGELOG.md
aliabid94 Dec 21, 2022
3ced7f8
changes
aliabid94 Dec 22, 2022
9f98cea
changes
aliabid94 Dec 28, 2022
efaaa34
changes
aliabid94 Dec 28, 2022
2ce6082
Merge remote-tracking branch 'origin' into progress
aliabid94 Dec 29, 2022
a759178
changes
aliabid94 Dec 29, 2022
14a0df7
changes
aliabid94 Dec 30, 2022
871fadb
change
aliabid94 Dec 30, 2022
58d6dfa
changes
aliabid94 Dec 30, 2022
61a07da
Update guides/01_getting_started/02_key_features.md
aliabid94 Dec 30, 2022
a1f4041
Update gradio/helpers.py
aliabid94 Dec 30, 2022
78e6c31
Update gradio/routes.py
aliabid94 Dec 30, 2022
4c76322
Update gradio/helpers.py
aliabid94 Dec 30, 2022
6fed596
Update guides/01_getting_started/02_key_features.md
aliabid94 Dec 30, 2022
ede2fb2
Update guides/01_getting_started/02_key_features.md
aliabid94 Dec 30, 2022
6c4b7ec
Update demo/progress_simple/run.py
aliabid94 Dec 30, 2022
795e163
Update demo/progress_simple/run.py
aliabid94 Dec 30, 2022
dc26716
Update demo/progress_simple/run.py
aliabid94 Dec 30, 2022
d6ee858
Update website/homepage/src/docs/template.html
aliabid94 Dec 30, 2022
96a8684
Update website/homepage/src/docs/template.html
aliabid94 Dec 30, 2022
fb6f8d7
changes
aliabid94 Dec 30, 2022
48e096f
Merge branch 'progress' of https://github.com/gradio-app/gradio into …
aliabid94 Dec 30, 2022
b5ec46d
changes
aliabid94 Dec 30, 2022
cfd35d2
changes
aliabid94 Dec 30, 2022
2da33db
changes
aliabid94 Dec 30, 2022
b8b4aaa
changes
aliabid94 Dec 30, 2022
8c35a66
changes
aliabid94 Dec 30, 2022
5bc8956
changes
aliabid94 Dec 30, 2022
ce6299a
change
aliabid94 Dec 30, 2022
2bda4e1
changes
aliabid94 Dec 30, 2022
9a86969
changes
aliabid94 Dec 30, 2022
e9ab760
changes
aliabid94 Dec 30, 2022
112ed39
change
aliabid94 Dec 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Upcoming Release

## New Features:

* Send custom progress updates by adding a `gr.Progress` argument after the input arguments to any function. Example:

```python
def reverse(word, progress=gr.Progress()):
progress(0, desc="Starting")
time.sleep(1)
new_string = ""
for letter in progress.tqdm(word, desc="Reversing"):
time.sleep(0.25)
new_string = letter + new_string
return new_string

demo = gr.Interface(reverse, gr.Text(), gr.Text())
```

Progress indicator bar by [@aliabid94](https://github.com/aliabid94) in [PR 2750](https://github.com/gradio-app/gradio/pull/2750).

* Added `title` argument to `TabbedInterface` by @MohamedAliRashad in [#2888](https://github.com/gradio-app/gradio/pull/2888)

## Bug Fixes:
Expand Down
2 changes: 2 additions & 0 deletions demo/progress/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tqdm
datasets
1 change: 1 addition & 0 deletions demo/progress/run.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: progress"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio tqdm datasets"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import random\n", "import time\n", "import tqdm\n", "from datasets import load_dataset\n", "import shutil\n", "from uuid import uuid4\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " text = gr.Textbox()\n", " textb = gr.Textbox()\n", " with gr.Row():\n", " load_set_btn = gr.Button(\"Load Set\")\n", " load_nested_set_btn = gr.Button(\"Load Nested Set\")\n", " load_random_btn = gr.Button(\"Load Random\")\n", " clean_imgs_btn = gr.Button(\"Clean Images\")\n", " wait_btn = gr.Button(\"Wait\")\n", " do_all_btn = gr.Button(\"Do All\")\n", " track_tqdm_btn = gr.Button(\"Bind TQDM\")\n", " bind_internal_tqdm_btn = gr.Button(\"Bind Internal TQDM\")\n", "\n", " text2 = gr.Textbox()\n", "\n", " # track list\n", " def load_set(text, text2, progress=gr.Progress()):\n", " imgs = [None] * 24\n", " for img in progress.tqdm(imgs, desc=\"Loading from list\"):\n", " time.sleep(0.1)\n", " return \"done\"\n", " load_set_btn.click(load_set, [text, textb], text2)\n", "\n", " # track nested list\n", " def load_nested_set(text, text2, progress=gr.Progress()):\n", " imgs = [[None] * 8] * 3\n", " for img_set in progress.tqdm(imgs, desc=\"Nested list\"):\n", " time.sleep(2)\n", " for img in progress.tqdm(img_set, desc=\"inner list\"):\n", " time.sleep(0.1)\n", " return \"done\"\n", " load_nested_set_btn.click(load_nested_set, [text, textb], text2)\n", "\n", " # track iterable of unknown length\n", " def load_random(data, progress=gr.Progress()):\n", " def yielder():\n", " for i in range(0, random.randint(15, 20)):\n", " time.sleep(0.1)\n", " yield None\n", " for img in progress.tqdm(yielder()):\n", " pass\n", " return \"done\"\n", " load_random_btn.click(load_random, {text, textb}, text2)\n", " \n", " # manual progress\n", " def clean_imgs(text, progress=gr.Progress()):\n", " progress(0.2, desc=\"Collecting Images\")\n", " time.sleep(1)\n", " progress(0.5, desc=\"Cleaning Images\")\n", " time.sleep(1.5)\n", " progress(0.8, desc=\"Sending Images\")\n", " time.sleep(1.5)\n", " return \"done\"\n", " clean_imgs_btn.click(clean_imgs, text, text2)\n", "\n", " # no progress\n", " def wait(text):\n", " time.sleep(4)\n", " return \"done\"\n", " wait_btn.click(wait, text, text2)\n", "\n", " # multiple progressions\n", " def do_all(data, progress=gr.Progress()):\n", " load_set(data[text], data[textb], progress)\n", " load_random(data, progress)\n", " clean_imgs(data[text], progress)\n", " progress(None)\n", " wait(text)\n", " return \"done\"\n", " do_all_btn.click(do_all, {text, textb}, text2)\n", "\n", " def track_tqdm(data, progress=gr.Progress(track_tqdm=True)):\n", " for i in tqdm.tqdm(range(5), desc=\"outer\"):\n", " for j in tqdm.tqdm(range(4), desc=\"inner\"):\n", " time.sleep(1)\n", " return \"done\"\n", " track_tqdm_btn.click(track_tqdm, {text, textb}, text2)\n", "\n", " def bind_internal_tqdm(data, progress=gr.Progress(track_tqdm=True)):\n", " outdir = \"__tmp/\" + str(uuid4())\n", " dataset = load_dataset(\"beans\", split=\"train\", cache_dir=outdir)\n", " shutil.rmtree(outdir)\n", " return \"done\"\n", " bind_internal_tqdm_btn.click(bind_internal_tqdm, {text, textb}, text2)\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.queue(concurrency_count=20).launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
97 changes: 97 additions & 0 deletions demo/progress/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import gradio as gr
import random
import time
import tqdm
aliabid94 marked this conversation as resolved.
Show resolved Hide resolved
from datasets import load_dataset
import shutil
from uuid import uuid4

with gr.Blocks() as demo:
with gr.Row():
text = gr.Textbox()
textb = gr.Textbox()
with gr.Row():
load_set_btn = gr.Button("Load Set")
load_nested_set_btn = gr.Button("Load Nested Set")
load_random_btn = gr.Button("Load Random")
clean_imgs_btn = gr.Button("Clean Images")
wait_btn = gr.Button("Wait")
do_all_btn = gr.Button("Do All")
track_tqdm_btn = gr.Button("Bind TQDM")
bind_internal_tqdm_btn = gr.Button("Bind Internal TQDM")

text2 = gr.Textbox()

# track list
def load_set(text, text2, progress=gr.Progress()):
imgs = [None] * 24
for img in progress.tqdm(imgs, desc="Loading from list"):
time.sleep(0.1)
return "done"
load_set_btn.click(load_set, [text, textb], text2)

# track nested list
def load_nested_set(text, text2, progress=gr.Progress()):
imgs = [[None] * 8] * 3
for img_set in progress.tqdm(imgs, desc="Nested list"):
time.sleep(2)
for img in progress.tqdm(img_set, desc="inner list"):
time.sleep(0.1)
return "done"
load_nested_set_btn.click(load_nested_set, [text, textb], text2)

# track iterable of unknown length
def load_random(data, progress=gr.Progress()):
def yielder():
for i in range(0, random.randint(15, 20)):
time.sleep(0.1)
yield None
for img in progress.tqdm(yielder()):
pass
return "done"
load_random_btn.click(load_random, {text, textb}, text2)

# manual progress
def clean_imgs(text, progress=gr.Progress()):
progress(0.2, desc="Collecting Images")
time.sleep(1)
progress(0.5, desc="Cleaning Images")
time.sleep(1.5)
progress(0.8, desc="Sending Images")
time.sleep(1.5)
return "done"
clean_imgs_btn.click(clean_imgs, text, text2)

# no progress
def wait(text):
time.sleep(4)
return "done"
wait_btn.click(wait, text, text2)

# multiple progressions
def do_all(data, progress=gr.Progress()):
load_set(data[text], data[textb], progress)
load_random(data, progress)
clean_imgs(data[text], progress)
progress(None)
wait(text)
return "done"
do_all_btn.click(do_all, {text, textb}, text2)

def track_tqdm(data, progress=gr.Progress(track_tqdm=True)):
for i in tqdm.tqdm(range(5), desc="outer"):
for j in tqdm.tqdm(range(4), desc="inner"):
time.sleep(1)
return "done"
track_tqdm_btn.click(track_tqdm, {text, textb}, text2)

def bind_internal_tqdm(data, progress=gr.Progress(track_tqdm=True)):
outdir = "__tmp/" + str(uuid4())
dataset = load_dataset("beans", split="train", cache_dir=outdir)
shutil.rmtree(outdir)
return "done"
bind_internal_tqdm_btn.click(bind_internal_tqdm, {text, textb}, text2)


if __name__ == "__main__":
demo.queue(concurrency_count=20).launch()
1 change: 1 addition & 0 deletions demo/progress_simple/run.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: progress_simple"]}, {"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", "\n", "def slowly_reverse(word, progress=gr.Progress()):\n", " progress(0, desc=\"Starting\")\n", " time.sleep(1)\n", " progress(0.05)\n", " new_string = \"\"\n", " for letter in progress.tqdm(word, desc=\"Reversing\"):\n", " time.sleep(0.25)\n", " new_string = letter + new_string\n", " return new_string\n", "\n", "demo = gr.Interface(slowly_reverse, gr.Text(), gr.Text())\n", "\n", "if __name__ == \"__main__\":\n", " demo.queue(concurrency_count=10).launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
17 changes: 17 additions & 0 deletions demo/progress_simple/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import gradio as gr
import time

def slowly_reverse(word, progress=gr.Progress()):
progress(0, desc="Starting")
time.sleep(1)
progress(0.05)
new_string = ""
for letter in progress.tqdm(word, desc="Reversing"):
time.sleep(0.25)
new_string = letter + new_string
return new_string

demo = gr.Interface(slowly_reverse, gr.Text(), gr.Text())

if __name__ == "__main__":
demo.queue(concurrency_count=10).launch()
7 changes: 4 additions & 3 deletions gradio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import gradio.outputs as outputs
import gradio.processing_utils
import gradio.templates
from gradio.blocks import Blocks, skip, update
from gradio.blocks import Blocks
from gradio.components import (
HTML,
JSON,
Expand Down Expand Up @@ -49,7 +49,6 @@
Video,
component,
)
from gradio.examples import create_examples as Examples
from gradio.exceptions import Error
from gradio.flagging import (
CSVLogger,
Expand All @@ -58,6 +57,9 @@
HuggingFaceDatasetSaver,
SimpleCSVLogger,
)
from gradio.helpers import Progress
from gradio.helpers import create_examples as Examples
from gradio.helpers import make_waveform, skip, update
from gradio.interface import Interface, TabbedInterface, close_all
from gradio.ipython_ext import load_ipython_extension
from gradio.layouts import Accordion, Box, Column, Group, Row, Tab, TabItem, Tabs
Expand All @@ -79,7 +81,6 @@
TextArea,
Webcam,
)
from gradio.utils import make_waveform

current_pkg_version = pkgutil.get_data(__name__, "version.txt").decode("ascii").strip()
__version__ = current_pkg_version
Loading