-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Improve file handling in JS Client #8462
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/c4265462b96bbf2dc247f9dd2b55fcf190dc3037/gradio-4.33.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@c4265462b96bbf2dc247f9dd2b55fcf190dc3037#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-builds.s3.amazonaws.com/c4265462b96bbf2dc247f9dd2b55fcf190dc3037/gradio-client-0.20.1.tgz |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
Another case that should work is when the const image_url = "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png";
const result = client.submit("/lambda", {
x: {
files: [handle_file(image_url), handle_file(image_url)]
}
}) |
client/js/src/utils/handle_blob.ts
Outdated
throw new Error(NODEJS_FS_ERROR_MSG); | ||
} | ||
|
||
const file = new File([fileBuffer], cmd_item.meta.name, { |
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.
We can't use File
in node, it was only added in v20, we can just use Blob
here instead. In theory we lose the filename but we lose it anyway. We can improve the filename handling later on.
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.
Apart from that File comment, it works perfectly. Awesome stuff, thanks @hannahblair!
Description
This PR adds a
handle_file
function, which converts aURL
orFile
toFileData
, or if it receives aBlob
, it will just return the Blob as the client handles that anyway. This PR also fixes an issue with image uploading.Methods of file handling that should work with this PR:
Passing a blob directly
Passing a blob to
handle_file
Passing an image URL to
handle_file
Passing an image URL as an object
Passing a local file path to
handle_file
Passing a
Buffer
tohandle_file
Passing an array of local image files to
handle_file
Closes: #6623
Closes: #8082
Closes: #7834
Closes: #8402
Clsoes: #8256
🎯 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