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

ensure @gradio/client always returns the correct data #8716

Merged
merged 5 commits into from
Jul 11, 2024
Merged

Conversation

pngwn
Copy link
Member

@pngwn pngwn commented Jul 8, 2024

Description

Closes #8508.

In handle_payload which we use to remove state data which is always null, we handle both inputs (request payload) and outputs (response payload) but we were treating everything as if they were inputs. So if there were no input components but there was data returned, it would be removed.

Can reproduce fix this script:

import { Client, handle_file } from "./dist/index.js";

async function generate(image_url) {
	const client = await Client.connect("TencentARC/InstantMesh", {
		events: ["status", "data"]
	});

	const image = await fetch(image_url);
	const image_blob = await image.blob();

	// This is working fine
	const result_mvs_image = await client.predict("/generate_mvs", [
		handle_file(image_blob),
		50,
		10000
	]);

	console.log(result_mvs_image);

	// This is returning empty data object
	const job = client.submit("/make3d", []);

	for await (const message of job) {
		if (message.type === "data") {
			console.log(message);
		}
	}
}

generate(
	"https://github.com/raw/gradio-app/gradio/main/test/test_files/bus.png"
);

Add it to client/js as test.js, run pnpm build and run node test.js.

🎯 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

@pngwn pngwn requested a review from hannahblair July 8, 2024 13:27
@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 8, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/da4ec7343dbf848047ec3f31d011242fa49727a6/gradio-4.37.2-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@da4ec7343dbf848047ec3f31d011242fa49727a6#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-builds.s3.amazonaws.com/da4ec7343dbf848047ec3f31d011242fa49727a6/gradio-client-1.2.1.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 8, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/client patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

ensure @gradio/client always returns the correct data

Maintainers or the PR author can modify the PR title to modify this entry.

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.

@@ -187,14 +187,15 @@ export function handle_payload(

let updated_payload: unknown[] = [];
let payload_index = 0;
for (let i = 0; i < dependency.inputs.length; i++) {
const input_id = dependency.inputs[i];
const deps = type === "input" ? dependency.inputs : dependency.outputs;
Copy link
Member Author

Choose a reason for hiding this comment

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

We just need to check which dependencies we care about here and set it accordingly, when handling inputs we use dependency.inputs when handling outputs we use dependency.outputs.

Comment on lines +44 to +47
name:
typeof File !== "undefined" && blob instanceof File
? blob?.name
: undefined
Copy link
Member Author

Choose a reason for hiding this comment

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

I was getting an error about File not being defined. This check fixes it.

Copy link
Collaborator

@hannahblair hannahblair left a comment

Choose a reason for hiding this comment

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

Ah dang, that's a bad bug. Thanks for fixing that @pngwn! Tested and works as expected.

Screenshot 2024-07-11 at 12 58 47

@pngwn pngwn merged commit e834d30 into main Jul 11, 2024
8 checks passed
@pngwn pngwn deleted the 8508-client-data branch July 11, 2024 12:15
@pngwn pngwn mentioned this pull request Jul 11, 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.

Data event return empty data object in JS client
3 participants