Skip to content

Commit d3966ca

Browse files
aliabid94Ali Abidgradio-pr-bot
authored
Restore Blocks constructor args deprecated in 6.0 (theme, css, etc.) (#12502)
* changes * add changeset * changes * Change warning type from DeprecationWarning to UserWarning --------- Co-authored-by: Ali Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 0715279 commit d3966ca

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

.changeset/young-insects-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gradio": minor
3+
---
4+
5+
feat:Restore Blocks constructor args deprecated in 6.0 (theme, css, etc.)

gradio/blocks.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,23 @@ def __init__(
10671067
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "True"
10681068
self.enable_monitoring: bool | None = None
10691069

1070+
deprecated_params = ["theme", "css", "css_paths", "js", "head", "head_paths"]
1071+
deprecated_kwargs = {k: kwargs.pop(k) for k in deprecated_params if k in kwargs}
1072+
if deprecated_kwargs:
1073+
param_list = ", ".join(deprecated_kwargs.keys())
1074+
warnings.warn(
1075+
f"The parameters have been moved from the Blocks constructor to the launch() method in Gradio 6.0: {param_list}. "
1076+
f"Please pass these parameters to launch() instead.",
1077+
UserWarning,
1078+
stacklevel=2,
1079+
)
1080+
self._deprecated_theme = deprecated_kwargs.get("theme")
1081+
self._deprecated_css = deprecated_kwargs.get("css")
1082+
self._deprecated_css_paths = deprecated_kwargs.get("css_paths")
1083+
self._deprecated_js = deprecated_kwargs.get("js")
1084+
self._deprecated_head = deprecated_kwargs.get("head")
1085+
self._deprecated_head_paths = deprecated_kwargs.get("head_paths")
1086+
10701087
self.default_config = BlocksConfig(self)
10711088
super().__init__(render=False, **kwargs)
10721089

@@ -2525,6 +2542,15 @@ def reverse(text):
25252542
# We have already launched the demo
25262543
return None, None, None # type: ignore
25272544

2545+
theme = theme if theme is not None else self._deprecated_theme
2546+
css = css if css is not None else self._deprecated_css
2547+
css_paths = css_paths if css_paths is not None else self._deprecated_css_paths
2548+
js = js if js is not None else self._deprecated_js
2549+
head = head if head is not None else self._deprecated_head
2550+
head_paths = (
2551+
head_paths if head_paths is not None else self._deprecated_head_paths
2552+
)
2553+
25282554
self.theme: Theme = utils.get_theme(theme)
25292555
self.css = css
25302556
self.css_paths = css_paths or []

0 commit comments

Comments
 (0)