-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
66c9b85
changes
aliabid94 fd97d93
version
abidlabs b475014
Merge branch 'main' into progress
abidlabs b52f921
changes
aliabid94 7ffcf79
changes
aliabid94 4e29cf7
fixes
aliabid94 1bc7788
changes
aliabid94 9c1ee0d
Merge remote-tracking branch 'origin' into progress
aliabid94 0f630b8
changes
aliabid94 10211c3
Merge remote-tracking branch 'origin' into progress
aliabid94 451050e
changes
aliabid94 2672e24
changes
aliabid94 316606f
chagnes
aliabid94 cec8100
Merge remote-tracking branch 'origin' into progress
aliabid94 799eeeb
chagnes
aliabid94 356bb3d
fix
aliabid94 fd65378
changes
aliabid94 0dd7a07
changes
aliabid94 7498c9b
changes
aliabid94 e6cd154
change
aliabid94 adc4ba3
changes
aliabid94 141f1a8
Merge remote-tracking branch 'origin' into progress
aliabid94 0ee8240
changes
aliabid94 4d1511e
changes
aliabid94 684e052
changes
aliabid94 dd0b78f
changes
aliabid94 7098773
changes
aliabid94 763c074
changes
aliabid94 0a9b830
changes
aliabid94 1885eb7
changes
aliabid94 7dc58d5
changes
aliabid94 7483d96
changes
aliabid94 96cc934
changes
aliabid94 d5195be
version update
aliabid94 f98b799
Commit from GitHub Actions (Upload Python Package)
aliabid94 0675d7f
merge change
aliabid94 84d2e57
changes
aliabid94 ecb871b
changes
aliabid94 97179af
changes
aliabid94 053c368
changes
aliabid94 e19fb20
fix
aliabid94 234cb72
Merge remote-tracking branch 'origin' into progress
aliabid94 1331d4f
changes
aliabid94 3411b15
changes
aliabid94 510bccc
changes
aliabid94 3b0b238
Update CHANGELOG.md
aliabid94 6f5bc0f
Update CHANGELOG.md
aliabid94 f0c22dc
Update CHANGELOG.md
aliabid94 3ced7f8
changes
aliabid94 9f98cea
changes
aliabid94 efaaa34
changes
aliabid94 2ce6082
Merge remote-tracking branch 'origin' into progress
aliabid94 a759178
changes
aliabid94 14a0df7
changes
aliabid94 871fadb
change
aliabid94 58d6dfa
changes
aliabid94 61a07da
Update guides/01_getting_started/02_key_features.md
aliabid94 a1f4041
Update gradio/helpers.py
aliabid94 78e6c31
Update gradio/routes.py
aliabid94 4c76322
Update gradio/helpers.py
aliabid94 6fed596
Update guides/01_getting_started/02_key_features.md
aliabid94 ede2fb2
Update guides/01_getting_started/02_key_features.md
aliabid94 6c4b7ec
Update demo/progress_simple/run.py
aliabid94 795e163
Update demo/progress_simple/run.py
aliabid94 dc26716
Update demo/progress_simple/run.py
aliabid94 d6ee858
Update website/homepage/src/docs/template.html
aliabid94 96a8684
Update website/homepage/src/docs/template.html
aliabid94 fb6f8d7
changes
aliabid94 48e096f
Merge branch 'progress' of https://github.com/gradio-app/gradio into …
aliabid94 b5ec46d
changes
aliabid94 cfd35d2
changes
aliabid94 2da33db
changes
aliabid94 b8b4aaa
changes
aliabid94 8c35a66
changes
aliabid94 5bc8956
changes
aliabid94 ce6299a
change
aliabid94 2bda4e1
changes
aliabid94 9a86969
changes
aliabid94 e9ab760
changes
aliabid94 112ed39
change
aliabid94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
Model3D, | ||
Number, | ||
Plot, | ||
ProgressBar, | ||
Radio, | ||
Slider, | ||
State, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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, | ||||||
*, | ||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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): | ||||||
""" | ||||||
|
18 changes: 18 additions & 0 deletions
18
ui/packages/app/src/components/ProgressBar/ProgressBar.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
None
do?