Ability to disable orange progress animation for generators (#8543)

* 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>
This commit is contained in:
Freddy Boulton 2024-06-12 15:46:29 -04:00 committed by GitHub
parent 81ae7663b3
commit a4433be25c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 3 deletions

View File

@ -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`.

View File

@ -80,6 +80,7 @@ class ChatInterface(Blocks):
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:
@ -109,6 +110,7 @@ class ChatInterface(Blocks):
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,
@ -308,7 +310,7 @@ class ChatInterface(Blocks):
self.chatbot_state = (
State(self.chatbot.value) if self.chatbot.value else State([])
)
self.show_progress = show_progress
self._setup_events()
self._setup_api()
@ -343,6 +345,9 @@ class ChatInterface(Blocks):
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)
@ -371,6 +376,9 @@ class ChatInterface(Blocks):
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)

View File

@ -9,7 +9,7 @@ import json
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
@ -131,6 +131,7 @@ class Interface(Blocks):
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,
):
"""
@ -166,6 +167,7 @@ class Interface(Blocks):
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,
@ -415,6 +417,7 @@ class Interface(Blocks):
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
@ -732,6 +735,9 @@ class Interface(Blocks):
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(

View File

@ -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"}