Skip to content

Commit ca125b7

Browse files
Fix reload mode for jupyter notebook and stateful demos (#8599)
* Remove deprecated method * add changeset * Fix bug * Update test * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 65afffd commit ca125b7

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

.changeset/grumpy-houses-raise.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@gradio/app": patch
3+
"gradio": patch
4+
---
5+
6+
fix:Fix reload mode for jupyter notebook and stateful demos

gradio/ipython_ext.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,27 @@ def track(self, demo: gr.Blocks):
5959
def load_ipython_extension(ipython):
6060
reloader = JupyterReloader(ipython)
6161

62-
@magic_arguments()
63-
@argument("--demo-name", default="demo", help="Name of gradio blocks instance.")
64-
@argument(
62+
@magic_arguments() # type: ignore
63+
@argument("--demo-name", default="demo", help="Name of gradio blocks instance.") # type: ignore
64+
@argument( # type: ignore
6565
"--share",
6666
default=False,
6767
const=True,
6868
nargs="?",
6969
help="Whether to launch with sharing. Will slow down reloading.",
7070
)
71-
@register_cell_magic
72-
@needs_local_scope
71+
@register_cell_magic # type: ignore
72+
@needs_local_scope # type: ignore
7373
def blocks(line, cell, local_ns):
7474
"""Launch a demo defined in a cell in reload mode."""
7575

76-
args = parse_argstring(blocks, line)
76+
args = parse_argstring(blocks, line) # type: ignore
7777

7878
exec(cell, None, local_ns)
7979
demo: gr.Blocks = local_ns[args.demo_name]
8080
if not reloader.demo_tracked():
8181
demo.launch(share=args.share)
8282
reloader.track(demo)
83-
elif reloader.queue_changed(demo):
84-
print("Queue got added or removed. Restarting demo.")
85-
reloader.running_demo.close()
86-
demo.launch()
87-
reloader.track(demo)
8883
else:
8984
reloader.swap_blocks(demo)
9085
return reloader.running_demo.artifact

js/app/src/Index.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
app.close();
319319
app = await Client.connect(api_url, {
320320
status_callback: handle_status,
321+
with_null_state: true,
321322
events: ["data", "log", "status", "render"]
322323
});
323324

js/app/test/test_chatinterface.reload.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ test("gradio dev mode correctly reloads a stateful ChatInterface demo", async ({
5858
import gradio as gr
5959
6060
def greet(msg, history):
61-
return "Hello"
61+
return f"You typed: {msg}"
6262
63-
demo = gr.ChatInterface(fn=greet, textbox=gr.Textbox(label="foo"))
63+
demo = gr.ChatInterface(fn=greet, textbox=gr.Textbox(label="foo", placeholder="Type a message..."))
6464
6565
if __name__ == "__main__":
6666
demo.launch()
@@ -75,6 +75,17 @@ if __name__ == "__main__":
7575
}
7676
});
7777
await expect(page.getByLabel("foo")).toBeVisible();
78+
const textbox = page.getByPlaceholder("Type a message...");
79+
const submit_button = page.getByRole("button", { name: "Submit" });
80+
81+
await textbox.fill("hello");
82+
await submit_button.click();
83+
84+
await expect(textbox).toHaveValue("");
85+
const response = page.locator(".bot p", {
86+
hasText: "You typed: hello"
87+
});
88+
await expect(response).toBeVisible();
7889
} finally {
7990
if (_process) kill_process(_process);
8091
}

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ exclude = [
104104
"gradio/themes/",
105105
"gradio/_frontend_code/",
106106
"gradio/components/*_plot.py",
107-
"gradio/ipython_ext.py",
108107
"gradio/node/*.py",
109108
"gradio/_frontend_code/*.py",
110109
]

0 commit comments

Comments
 (0)