Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client Release Notes #8468

Merged
merged 7 commits into from
Jun 6, 2024
Merged

Client Release Notes #8468

merged 7 commits into from
Jun 6, 2024

Conversation

freddyaboulton
Copy link
Collaborator

Description

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jun 5, 2024

🪼 branch checks and previews

Name Status URL
Website building...
🦄 Changes detected! Details

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jun 5, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/client major
gradio_client major

With the following changelog entry.

Clients 1.0 Launch!

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 the Client class was removed. Has no effect.
  • The upload_files argument of the Client 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 the download_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 to gr.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 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 and fetch_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.

⚠️ The changeset file for this pull request has been modified manually, so the changeset generation bot has been disabled. To go back into automatic mode, delete the changeset file.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.


**Stream From a Gradio APP in 5 lines**

Use the `submit` method to get a job you can iterate over:
Copy link
Member

@abidlabs abidlabs Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think we should have a "regular" .predict() example first before an iterator example?


If something goes wrong in the upstream app, the client will raise the same exception as the app provided it's a `gr.Error` exception.

#### Transparent Design 🪟
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @freddyaboulton! I left a few minor points of feedback

@abidlabs abidlabs marked this pull request as ready for review June 6, 2024 12:39
@abidlabs
Copy link
Member

abidlabs commented Jun 6, 2024

confirmed lgtm from @hannahblair as well, so will merge this in

@abidlabs abidlabs merged commit 7cc0a0c into main Jun 6, 2024
7 checks passed
@abidlabs abidlabs deleted the client-release branch June 6, 2024 13:21
This was referenced Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants