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
Return final output for generators in Client.predict #5057
Conversation
0f12998
to
9846d4d
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🎉 Chromatic build completed! There are 0 visual changes to review. |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-5057-all-demos You can install the changes in this PR by running: pip install https://gradio-builds.s3.amazonaws.com/35150c1a8a0aea0771cc97232634093ce19e102f/gradio-3.39.0-py3-none-any.whl |
6653df7
to
5877ef0
Compare
5877ef0
to
1352f10
Compare
caecc69
to
9b27061
Compare
client/js/src/client.ts
Outdated
return { on, off, cancel, destroy, finish }; | ||
} | ||
|
||
async function finish() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice js!
Looks good @freddyaboulton! I tested the Python client and works great. Trying to figure out how to test the JS client right now. A thought in the meantime -- I know we discussed this before and I was initially against it -- but should we just have the Pros:
Cons:
|
I agree it's what people expect! Ok let's do that. |
client/js/src/client.ts
Outdated
let result; | ||
|
||
app | ||
.on("data", (d) => { | ||
data_returned = true; | ||
if (status_complete) { | ||
app.destroy(); | ||
data_returned = true; | ||
res(d); | ||
} | ||
res(d); | ||
result = d; | ||
}) | ||
.on("status", (status) => { | ||
if (status.stage === "error") rej(status); | ||
if (status.stage === "complete" && data_returned) { | ||
app.destroy(); | ||
} | ||
if (status.stage === "complete") { | ||
status_complete = true; | ||
app.destroy(); | ||
res(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats this stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to returning the final output of a generator.
Works in my tests but let me know if there’s a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh of course, my bad.
The only problem is it was implemented this way because i was having an issue receiving message out of order, which isn't technically supposed to be possible but it still happened. So the original logic allowed either message to resolve the promise whereas this only allows the status function to finish it, which if it is processed before the final data message means that the return value of predict would be the second to last value.
Maybe we could use the data.completed
property and add the dual handling back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I added the dual handling back
4f9b51b
to
d1b9dbe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks @freddyaboulton!
Thank you @pngwn !! |
Description
Closes #4887
Closes #4888
Adds a
finish
method to the client jobs to make it easier to wait for job completion.Also installs the client locally for CI as discussed in #4888
Python
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
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
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh