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 1 commit
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
28 changes: 28 additions & 0 deletions demo/progress/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import gradio as gr
import random
import time


with gr.Blocks() as demo:
btn = gr.Button("Go")
progress = gr.ProgressBar(visible=False)
num = gr.Number()

def dummy():
yield {progress: gr.ProgressBar.update(value=0, visible=True)}
total_duration = random.randint(3, 10)
duration = 0
while duration < total_duration:
yield {progress: duration / total_duration}
time.sleep(1)
duration += 1
yield {
progress: gr.ProgressBar.update(visible=False),
num: random.randint(0, 100),
}

btn.click(dummy, None, {num, progress})


if __name__ == "__main__":
demo.queue().launch()
1 change: 1 addition & 0 deletions gradio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
Model3D,
Number,
Plot,
ProgressBar,
Radio,
Slider,
State,
Expand Down
45 changes: 45 additions & 0 deletions gradio/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,51 @@ def style(self, *, full_width: Optional[bool] = None, **kwargs):
return IOComponent.style(self, **kwargs)


@document()
class ProgressBar(IOComponent, SimpleSerializable):
"""
Used to create a progress bar, with a value between 0 and 1 representing progress level, or None indicating unknown progress duration.

Preprocessing: passes the progress value as a {float} into the function
Postprocessing: expects a {float} between 0 and 1 to be returned from a function, which is set as the progress level.
Demos: blocks_xray
"""

def __init__(
self,
value: float | None = 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does None do?

*,
visible: bool = True,
elem_id: Optional[str] = None,
**kwargs,
):
"""
Parameters:
value: Default text for the button to display. If callable, the function will be called whenever the app loads to set the initial value of the component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value: Default text for the button to display. If callable, the function will be called whenever the app loads to set the initial value of the component.
value: value of the progress bar -- should be a `float` between 0 or 1.

visible: If False, component will be hidden.
elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
"""
IOComponent.__init__(
self, visible=visible, elem_id=elem_id, value=value, **kwargs
)

def get_config(self):
return {
"value": self.value,
**Component.get_config(self),
}

@staticmethod
def update(
value: Optional[str] = _Keywords.NO_VALUE,
visible: Optional[bool] = None,
):
return {
"visible": visible,
"value": value,
"__type__": "update",
}

@document("change", "submit", "style")
class ColorPicker(Changeable, Submittable, IOComponent, SimpleSerializable):
"""
Expand Down
18 changes: 18 additions & 0 deletions ui/packages/app/src/components/ProgressBar/ProgressBar.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
export let value: number = 0;
export let visible: boolean = true;
$: _value = (Math.max(Math.min(1, value), 0) * 100).toFixed(1);
</script>

<div
class="w-full bg-gray-50 dark:bg-gray-700 h-9 relative rounded flex justify-center items-center"
class:hidden={visible === false}
>
<div class="absolute top-0 left-0 h-full w-full rounded">
<div
class="h-full rounded bg-gradient-to-b from-orange-500 to-orange-600 text-center truncate transition-all z-10"
style="width: {_value}%"
/>
</div>
<div class="py-0.5 px-2 bg-gray-900 bg-opacity-40 z-10 rounded-sm font-mono">{_value}%</div>
</div>
8 changes: 8 additions & 0 deletions ui/packages/app/src/components/ProgressBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { default as Component } from "./ProgressBar.svelte";
export const modes = ["static", "dynamic"];

export const document = (config: Record<string, any>) => ({
type: "number",
description: "progress level between 0 and 1",
example_data: 0.5
});
1 change: 1 addition & 0 deletions ui/packages/app/src/components/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const component_map = {
model3d: () => import("./Model3D"),
number: () => import("./Number"),
plot: () => import("./Plot"),
progressbar: () => import("./ProgressBar"),
radio: () => import("./Radio"),
row: () => import("./Row"),
slider: () => import("./Slider"),
Expand Down