From 6653df7d6b0aad788457889c3870345084bb085a Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Tue, 1 Aug 2023 11:35:35 -0400 Subject: [PATCH] Add feat changeset --- .changeset/two-spies-shine.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.changeset/two-spies-shine.md b/.changeset/two-spies-shine.md index 2b22d8936811f..d0aa255a97a19 100644 --- a/.changeset/two-spies-shine.md +++ b/.changeset/two-spies-shine.md @@ -6,4 +6,23 @@ highlight: -#### Use submit in View API page for generators +#### Better Code Snippet for Streaming API Routes + +Previously, the `View API` page would always use the `predict` method of the python client. However, this would only return the first output for routes that stream results. + +API routes that stream results will now use the `submit` method as opposed to `predict`. This also highlights the new `wait` method of the python client, which lets block until a job is finished + +```python +from gradio_client import Client + +client = Client("http://localhost:7860/") +# This api route streams outputs +result = client.submit( + 1, # int | float (numeric value between 1 and 10) in 'steps' Slider component + api_name="/predict" +) +result.wait(timeout=None) + +# Get the final output. outputs() returns a list of all streamed results. +print(result.outputs()[-1]) +``` \ No newline at end of file