Skip to content

Commit

Permalink
Ability to disable orange progress animation for generators (#8543)
Browse files Browse the repository at this point in the history
* Add code

* deletion

* add changeset

* add changeset

* Update nasty-actors-kick.md

Update changelog

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot committed Jun 12, 2024
1 parent 81ae766 commit a4433be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/nasty-actors-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/statustracker": patch
"gradio": patch
---

fix:Ability to disable orange progress animation for generators by setting `show_progress='minimal'` or `show_progress='hidden'` in the event definition. This is a small visual breaking change but it aligns better with the expected behavior of the `show_progress` parameter. Also added `show_progress` to `gr.Interface` and `gr.ChatInterface`.
10 changes: 9 additions & 1 deletion gradio/chat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
concurrency_limit: int | None | Literal["default"] = "default",
fill_height: bool = True,
delete_cache: tuple[int, int] | None = None,
show_progress: Literal["full", "minimal", "hidden"] = "minimal",
):
"""
Parameters:
Expand Down Expand Up @@ -109,6 +110,7 @@ def __init__(
concurrency_limit: If set, this is the maximum number of chatbot submissions that can be running simultaneously. Can be set to None to mean no limit (any number of chatbot submissions can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `.queue()`, which is 1 by default).
fill_height: If True, the chat interface will expand to the height of window.
delete_cache: A tuple corresponding [frequency, age] both expressed in number of seconds. Every `frequency` seconds, the temporary files created by this Blocks instance will be deleted if more than `age` seconds have passed since the file was created. For example, setting this to (86400, 86400) will delete temporary files every day. The cache will be deleted entirely when the server restarts. If None, no cache deletion will occur.
show_progress: whether to show progress animation while running.
"""
super().__init__(
analytics_enabled=analytics_enabled,
Expand Down Expand Up @@ -308,7 +310,7 @@ def __init__(
self.chatbot_state = (
State(self.chatbot.value) if self.chatbot.value else State([])
)

self.show_progress = show_progress
self._setup_events()
self._setup_api()

Expand Down Expand Up @@ -343,6 +345,9 @@ def _setup_events(self) -> None:
concurrency_limit=cast(
Union[int, Literal["default"], None], self.concurrency_limit
),
show_progress=cast(
Literal["full", "minimal", "hidden"], self.show_progress
),
)
)
self._setup_stop_events(submit_triggers, submit_event)
Expand Down Expand Up @@ -371,6 +376,9 @@ def _setup_events(self) -> None:
concurrency_limit=cast(
Union[int, Literal["default"], None], self.concurrency_limit
),
show_progress=cast(
Literal["full", "minimal", "hidden"], self.show_progress
),
)
)
self._setup_stop_events([self.retry_btn.click], retry_event)
Expand Down
8 changes: 7 additions & 1 deletion gradio/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import warnings
import weakref
from typing import TYPE_CHECKING, Any, Callable, Literal
from typing import TYPE_CHECKING, Any, Callable, Literal, cast

from gradio_client.documentation import document

Expand Down Expand Up @@ -131,6 +131,7 @@ def __init__(
stop_btn: str | Button = "Stop",
clear_btn: str | Button | None = "Clear",
delete_cache: tuple[int, int] | None = None,
show_progress: Literal["full", "minimal", "hidden"] = "full",
**kwargs,
):
"""
Expand Down Expand Up @@ -166,6 +167,7 @@ def __init__(
stop_btn: The button to use for stopping the interface. Defaults to a `gr.Button("Stop", variant="stop", visible=False)`. Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization).
clear_btn: The button to use for clearing the inputs. Defaults to a `gr.Button("Clear", variant="secondary")`. Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization). Can be set to None, which hides the button.
delete_cache: A tuple corresponding [frequency, age] both expressed in number of seconds. Every `frequency` seconds, the temporary files created by this Blocks instance will be deleted if more than `age` seconds have passed since the file was created. For example, setting this to (86400, 86400) will delete temporary files every day. The cache will be deleted entirely when the server restarts. If None, no cache deletion will occur.
show_progress: whether to show progress animation while running. Has no effect if the interface is `live`.
"""
super().__init__(
analytics_enabled=analytics_enabled,
Expand Down Expand Up @@ -415,6 +417,7 @@ def __init__(

self.flagging_callback = flagging_callback
self.flagging_dir = flagging_dir
self.show_progress = show_progress

self.batch = batch
self.max_batch_size = max_batch_size
Expand Down Expand Up @@ -732,6 +735,9 @@ async def cleanup():
batch=self.batch,
max_batch_size=self.max_batch_size,
concurrency_limit=self.concurrency_limit,
show_progress=cast(
Literal["full", "minimal", "hidden"], self.show_progress
),
)

final_event = predict_event.then(
Expand Down
2 changes: 1 addition & 1 deletion js/statustracker/static/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
(status === "pending" || status === "error")) ||
translucent ||
show_progress === "minimal"}
class:generating={status === "generating"}
class:generating={status === "generating" && show_progress === "full"}
class:border
style:position={absolute ? "absolute" : "static"}
style:padding={absolute ? "0" : "var(--size-8) 0"}
Expand Down

0 comments on commit a4433be

Please sign in to comment.