Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
37 KiB
@gradio/client
1.2.1
Features
1.2.0
Features
- #8489
c2a0d05
- Control Display of Error, Info, Warning. Thanks @freddyaboulton! - #8571
a77877f
- First time loading performance optimization. Thanks @baojianting! - #8600
7289c4b
- Add credentials: include and Cookie header to prevent 401 error. Thanks @yinkiu602! - #8522
bdaa678
- add handle_file docs. Thanks @pngwn!
Fixes
- #8521
900cf25
- Ensure frontend functions work when they don't return a value. Thanks @pngwn! - #8548
7fc0f51
- Fix reload mode by implementingclose
on the client. Thanks @freddyaboulton!
1.1.1
Features
1.1.0
Features
- #8483
e2271e2
- documentation for @gradio/client. Thanks @pngwn! - #8485
f8ebace
- Ensure all status are reported internally when callingpredict
. Thanks @pngwn!
1.0.0
Highlights
Clients 1.0 Launch! (#8468 7cc0a0c
)
We're excited to unveil the first major release of the Gradio clients. We've made it even easier to turn any Gradio application into a production endpoint thanks to the clients' ergonomic, transparent, and portable design.
Ergonomic API 💆
Stream From a Gradio app in 5 lines
Use the submit
method to get a job you can iterate over:
from gradio_client import Client
client = Client("gradio/llm_stream")
for result in client.submit("What's the best UI framework in Python?"):
print(result)
import { Client } from "@gradio/client";
const client = await Client.connect("gradio/llm_stream")
const job = client.submit("/predict", {"text": "What's the best UI framework in Python?"})
for await (const msg of job) console.log(msg.data)
Use the same keyword arguments as the app
from gradio_client import Client
client = Client("http://127.0.0.1:7860/")
result = client.predict(
message="Hello!!",
system_prompt="You are helpful AI.",
tokens=10,
api_name="/chat"
)
print(result)
import { Client } from "@gradio/client";
const client = await Client.connect("http://127.0.0.1:7860/");
const result = await client.predict("/chat", {
message: "Hello!!",
system_prompt: "Hello!!",
tokens: 10,
});
console.log(result.data);
Better Error Messages
If something goes wrong in the upstream app, the client will raise the same exception as the app provided that show_error=True
in the original app's launch()
function, or it's a gr.Error
exception.
Transparent Design 🪟
Anything you can do in the UI, you can do with the client:
- 🔒 Authentication
- 🛑 Job Cancelling
- ℹ️ Access Queue Position and API
- 📕 View the API information
Here's an example showing how to display the queue position of a pending job:
from gradio_client import Client
client = Client("gradio/diffusion_model")
job = client.submit("A cute cat")
while not job.done():
status = job.status()
print(f"Current in position {status.rank} out of {status.queue_size}")
Portable Design ⛺️
The client can run from pretty much any python and javascript environment (node, deno, the browser, Service Workers).
Here's an example using the client from a Flask server using gevent:
from gevent import monkey
monkey.patch_all()
from gradio_client import Client
from flask import Flask, send_file
import time
app = Flask(__name__)
imageclient = Client("gradio/diffusion_model")
@app.route("/gen")
def gen():
result = imageclient.predict(
"A cute cat",
api_name="/predict"
)
return send_file(result)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
1.0 Migration Guide and Breaking Changes
Python
- The
serialize
argument of theClient
class was removed. Has no effect. - The
upload_files
argument of theClient
was removed. - All filepaths must be wrapped in the
handle_file
method. Example:
from gradio_client import Client, handle_file
client = Client("gradio/image_captioner")
client.predict(handle_file("cute_cat.jpg"))
- The
output_dir
argument was removed. It is not specified in thedownload_files
argument.
Javascript
The client has been redesigned entirely. It was refactored from a function into a class. An instance can now be constructed by awaiting the connect
method.
const app = await Client.connect("gradio/whisper")
The app variable has the same methods as the python class (submit
, predict
, view_api
, duplicate
).
Additional Changes
- #8243 - Set orig_name in python client file uploads.
- #8264 - Make exceptions in the Client more specific.
- #8247 - Fix api recorder.
- #8276 - Fix bug where client could not connect to apps that had self signed certificates.
- #8245 - Cancel server progress from the python client.
- #8200 - Support custom components in gr.load
- #8182 - Convert sse calls in client from async to sync.
- #7732 - Adds support for kwargs and default arguments in the python client, and improves how parameter information is displayed in the "view API" page.
- #7888 - Cache view_api info in server and python client.
- #7575 - Files should now be supplied as
file(...)
in the Client, and some fixes togr.load()
as well. - #8401 - Add CDN installation to JS docs.
- #8299 - Allow JS Client to work with authenticated spaces 🍪.
- #8408 - Connect heartbeat if state created in render. Also fix config cleanup bug #8407.
- #8258 - Improve URL handling in JS Client.
- #8322 - ensure the client correctly handles all binary data.
- #8296 - always create a jwt when connecting to a space if a hf_token is present.
- #8285 - use the correct query param to pass the jwt to the heartbeat event.
- #8272 - ensure client works for private spaces.
- #8197 - Add support for passing keyword args to
data
in JS client. - #8252 - Client node fix.
- #8209 - Rename
eventSource_Factory
andfetch_implementation
. - #8109 - Implement JS Client tests.
- #8211 - remove redundant event source logic.
- #8179 - rework upload to be a class method + pass client into each component.
- #8181 - Ensure connectivity to private HF spaces with SSE protocol.
- #8169 - Only connect to heartbeat if needed.
- #8118 - Add eventsource polyfill for Node.js and browser environments.
- #7646 - Refactor JS Client.
- #7974 - Fix heartbeat in the js client to be Lite compatible.
- #7926 - Fixes streaming event race condition.
Thanks @freddyaboulton!
Features
Fixes
- #8477
d5a9604
- Fix js client bundle. Thanks @pngwn! - #8451
9d2d605
- Change client submit API to be an AsyncIterable and support more platforms. Thanks @pngwn! - #8462
6447dfa
- Improve file handling in JS Client. Thanks @hannahblair! - #8439
63d36fb
- Handle gradio apps usingstate
in the JS Client. Thanks @hannahblair!
0.20.1
Features
0.20.0
Features
- #8401
d078621
- Add CDN installation to JS docs. Thanks @hannahblair! - #8243
55f664f
- Add event listener support to render blocks. Thanks @aliabid94! - #8398
945ac83
- Improve rendering. Thanks @aliabid94! - #8299
ab65360
- Allow JS Client to work with authenticated spaces 🍪. Thanks @hannahblair!
Fixes
- #8408
e86dd01
- Connect heartbeat if state created in render. Also fix config cleanup bug #8407. Thanks @freddyaboulton! - #8258
1f8e5c4
- Improve URL handling in JS Client. Thanks @hannahblair!
0.19.4
Fixes
0.19.3
Features
Fixes
- #8296
929d216
- always create a jwt when connecting to a space if a hf_token is present. Thanks @pngwn!
0.19.2
Fixes
0.19.1
Fixes
0.19.0
Features
- #8110
5436031
- Render decorator 2. Thanks @aliabid94! - #8197
e09b4e8
- Add support for passing keyword args todata
in JS client. Thanks @hannahblair!
Fixes
0.18.0
Features
- #8121
f5b710c
- chore(deps): update dependency eslint to v9. Thanks @renovate! - #8209
b9afe93
- RenameeventSource_Factory
andfetch_implementation
. Thanks @hannahblair! - #8109
bed2f82
- Implement JS Client tests. Thanks @hannahblair! - #8211
91b5cd6
- remove redundant event source logic. Thanks @hannahblair!
Fixes
- #8179
6a218b4
- rework upload to be a class method + pass client into each component. Thanks @pngwn! - #8181
cf52ca6
- Ensure connectivity to private HF spaces with SSE protocol. Thanks @hannahblair! - #8169
3a6f1a5
- Only connect to heartbeat if needed. Thanks @freddyaboulton! - #8118
7aca673
- Add eventsource polyfill for Node.js and browser environments. Thanks @hannahblair!
0.17.0
Highlights
Setting File Upload Limits (#7909 2afca65
)
We have added a max_file_size
size parameter to launch()
that limits to size of files uploaded to the server. This limit applies to each individual file. This parameter can be specified as a string or an integer (corresponding to the size in bytes).
The following code snippet sets a max file size of 5 megabytes.
import gradio as gr
demo = gr.Interface(lambda x: x, "image", "image")
demo.launch(max_file_size="5mb")
# or
demo.launch(max_file_size=5 * gr.FileSize.MB)
Error states can now be cleared
When a component encounters an error, the error state shown in the UI can now be cleared by clicking on the x
icon in the top right of the component. This applies to all types of errors, whether it's raised in the UI or the server.
Thanks @freddyaboulton!
Features
- #8056
2e469a5
- Using keys to preserve values between reloads. Thanks @aliabid94! - #7646
450b8cc
- Refactor JS Client. Thanks @hannahblair! - #8061
17e83c9
- Docs Reorg and Intro Page. Thanks @aliabd!
Fixes
0.16.0
Features
Fixes
0.15.1
Fixes
0.15.0
Highlights
Automatically delete state after user has disconnected from the webpage (#7829 6a4bf7a
)
Gradio now automatically deletes gr.State
variables stored in the server's RAM when users close their browser tab.
The deletion will happen 60 minutes after the server detected a disconnect from the user's browser.
If the user connects again in that timeframe, their state will not be deleted.
Additionally, Gradio now includes a Blocks.unload()
event, allowing you to run arbitrary cleanup functions when users disconnect (this does not have a 60 minute delay).
You can think of the unload
event as the opposite of the load
event.
with gr.Blocks() as demo:
gr.Markdown(
"""# State Cleanup Demo
🖼️ Images are saved in a user-specific directory and deleted when the users closes the page via demo.unload.
""")
with gr.Row():
with gr.Column(scale=1):
with gr.Row():
img = gr.Image(label="Generated Image", height=300, width=300)
with gr.Row():
gen = gr.Button(value="Generate")
with gr.Row():
history = gr.Gallery(label="Previous Generations", height=500, columns=10)
state = gr.State(value=[], delete_callback=lambda v: print("STATE DELETED"))
demo.load(generate_random_img, [state], [img, state, history])
gen.click(generate_random_img, [state], [img, state, history])
demo.unload(delete_directory)
demo.launch(auth=lambda user,pwd: True,
auth_message="Enter any username and password to continue")
Thanks @freddyaboulton!
0.14.0
Features
Fixes
0.13.0
Fixes
- #7575
d0688b3
- Files should now be supplied asfile(...)
in the Client, and some fixes togr.load()
as well. Thanks @abidlabs!
0.12.2
Features
- #7528
eda33b3
- Refactorsget_fetchable_url_or_file()
to remove it from the frontend. Thanks @abidlabs! - #7340
4b0d589
- chore(deps): update all non-major dependencies. Thanks @renovate!
0.12.1
Fixes
- #7411
32b317f
- Setroot
correctly for Gradio apps that are deployed behind reverse proxies. Thanks @abidlabs!
0.12.0
Features
- #7183
49d9c48
- [WIP] Refactor file normalization to be in the backend and remove it from the frontend of each component. Thanks @abidlabs!
0.11.0
Features
- #7102
68a54a7
- Improve chatbot streaming performance with diffs. Thanks @aliabid94!/n Note that this PR changes the API format for generator functions, which would be a breaking change for any clients reading the EventStream directly
0.10.1
Fixes
- #7055
3c3cf86
- Fix UI freeze on rapid generators. Thanks @aliabid94!
0.10.0
Features
- #6931
6c863af
- Fix functional tests. Thanks @aliabid94! - #6820
649cd4d
- UseEventSource_factory
inopen_stream()
for Wasm. Thanks @whitphx!
0.9.4
Fixes
- #6863
d406855
- Fix JS Client when app is running behind a proxy. Thanks @freddyaboulton!
0.9.3
Features
- #6814
828fb9e
- Refactor queue so that there are separate queues for each concurrency id. Thanks @aliabid94!
0.9.2
Features
- #6798
245d58e
- Improve how server/js client handle unexpected errors. Thanks @freddyaboulton!
0.9.1
Fixes
- #6693
34f9431
- Python client properly handles hearbeat and log messages. Also handles responses longer than 65k. Thanks @freddyaboulton!
0.9.0
Features
Fixes
- #6556
d76bcaa
- Fix api event drops. Thanks @aliabid94!
0.8.2
Features
- #6511
71f1a1f99
- MarkFileData.orig_name
optional on the frontend aligning the type definition on the Python side. Thanks @whitphx!
0.8.1
Fixes
- #6383
324867f63
- Fix event target. Thanks @aliabid94!
0.8.0
Features
- #6307
f1409f95e
- Provide status updates on file uploads. Thanks @freddyaboulton!
0.7.2
Fixes
- #6327
bca6c2c80
- Restore query parameters in request. Thanks @aliabid94!
0.7.1
Features
- #6137
2ba14b284
- JS Param. Thanks @dawoodkhan82!
0.7.0
Features
- #5498
287fe6782
- fix circular dependency with client + upload. Thanks @pngwn! - #5498
287fe6782
- Image v4. Thanks @pngwn! - #5498
287fe6782
- Swap websockets for SSE. Thanks @pngwn!
0.7.0-beta.1
Features
- #6143
e4f7b4b40
- fix circular dependency with client + upload. Thanks @pngwn! - #6094
c476bd5a5
- Image v4. Thanks @pngwn! - #6069
bf127e124
- Swap websockets for SSE. Thanks @aliabid94!
0.7.0-beta.0
Features
- #6016
83e947676
- Format js in v4 branch. Thanks @freddyaboulton!
Fixes
0.6.0
Features
- #5972
11a300791
- Lite: Support opening the entrypoint HTML page directly in browser via thefile:
protocol. Thanks @whitphx!
0.5.2
Fixes
- #5840
4e62b8493
- Ensure websocket polyfill doesn't load if there is already aglobal.Webocket
property set. Thanks @Jay2theWhy!
0.5.1
Fixes
- #5816
796145e2c
- Fix calls to the component server so thatgr.FileExplorer
works on Spaces. Thanks @abidlabs!
0.5.0
Highlights
new FileExplorer
component (#5672 e4a307ed6
)
Thanks to a new capability that allows components to communicate directly with the server without passing data via the value, we have created a new FileExplorer
component.
This component allows you to populate the explorer by passing a glob, but only provides the selected file(s) in your prediction function.
Users can then navigate the virtual filesystem and select files which will be accessible in your predict function. This component will allow developers to build more complex spaces, with more flexible input options.
For more information check the FileExplorer
documentation.
Thanks @aliabid94!
Features
- #5787
caeee8bf7
- ensure the client does not depend onwindow
when running in a node environment. Thanks @gibiee!
Fixes
- #5776
c0fef4454
- Revert replica proxy logic and instead implement using theroot
variable. Thanks @freddyaboulton!
0.4.2
Features
0.4.1
Fixes
- #5705
78e7cf516
- ensure internal data has updated before dispatchingsuccess
orthen
events. Thanks @pngwn!
0.4.0
Features
- #5682
c57f1b75e
- Fix functional tests. Thanks @abidlabs! - #5681
40de3d217
- add query parameters to thegr.Request
object through thequery_params
attribute. Thanks @DarhkVoyd! - #5653
ea0e00b20
- Prevent Clients from accessing API endpoints that setapi_name=False
. Thanks @abidlabs!
0.3.1
Fixes
- #5412
26fef8c7
- Skip view_api request in js client when auth enabled. Thanks @freddyaboulton!
0.3.0
Features
- #5267
119c8343
- Faster reload mode. Thanks @freddyaboulton!
0.2.1
Features
- #5173
730f0c1d
- Ensure gradio client works as expected for functions that return nothing. Thanks @raymondtri!
0.2.0
Features
- #5133
61129052
- Update dependency esbuild to ^0.19.0. Thanks @renovate! - #5035
8b4eb8ca
- JS Client: Fixes cannot read properties of null (reading 'is_file'). Thanks @raymondtri!
Fixes
0.1.4
Patch Changes
0.1.3
Patch Changes
0.1.2
Patch Changes
-
#4273
1d0f0a9d
Thanks @pngwn! - Ensure websocket error messages are correctly handled. -
#4271
1151c525
Thanks @pngwn! - Ensure the full root path is always respected when making requests to a gradio app server.
0.1.1
Patch Changes
-
#4201
da5b4ee1
Thanks @pngwn! - Ensure semiver is bundled so CDN links work correctly. -
#4202
a26e9afd
Thanks @pngwn! - Ensure all URLs returned by the client are complete URLs with the correct host instead of an absolute path relative to a server.