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

Allow Python Client to upload/download files when connecting to Gradio apps with auth enabled #7555

Merged
merged 8 commits into from Mar 4, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Feb 27, 2024

Continuing the streak of auth-related fixes. This PR fixes: #6717

I've added a test, but you can also test that it works with Spaces:

from gradio_client import Client

client = Client("abidlabs/auth2", auth=("tom", "tom"))
client.predict("cheetah.jpg")

Also just did some minor cleanup of the relevant code

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 27, 2024

🪼 branch checks and previews

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

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/1c2390a13fea025afeb7a6acd7f66025a442a272/gradio-4.19.2-py3-none-any.whl

Install Gradio Python Client from this PR

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

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 27, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
gradio_client patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Allow Python Client to upload/download files when connecting to Gradio apps with auth enabled

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.

S3Studio added a commit to S3Studio/GPT-SoVITS that referenced this pull request Mar 1, 2024
If auth is set to gradio, calling from gradio_client to api will fail with exception:
server rejected WebSocket connection: HTTP 403
Current gradio version in GPT-SoVITS is 3.38.0 and official fix is on 4.9.0 according to:
gradio-app/gradio#6605
This commit upgrades gradio to latest version of 4.19.2 and modified deprecated arguments in code, and will fix server-side problem.
On the other hand, the client-side of gradio_client of the latest version of 0.10.1 raises a new exception when uploading a file to a api protected by auth:
ValueError: None
The fix for the problem has no effect to the server-side due to ongoing pull request:
gradio-app/gradio#7555
so this commit may be useful.
Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

lgtm! nice work

@@ -731,7 +731,7 @@ def _login(self, auth: tuple[str, str]):
data={"username": auth[0], "password": auth[1]},
)
if not resp.is_success:
raise ValueError(f"Could not login to {self.src}")
raise AuthenticationError(f"Could not login to {self.src}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

just fyi this will raise even when the problem isn't authentication, but the link being down for example because the space is sleeping. don't think it matters but if you want to make it strictly for authentication like you described in exceptions.py you should look at the status code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch, will fix

@abidlabs
Copy link
Member Author

abidlabs commented Mar 4, 2024

Thanks @aliabd! Appreciate the review -- made the fix and will merge it in after CI

@abidlabs abidlabs merged commit fc4c2db into main Mar 4, 2024
7 checks passed
@abidlabs abidlabs deleted the auth-download branch March 4, 2024 16:07
@pngwn pngwn mentioned this pull request Mar 4, 2024
@djaym7
Copy link

djaym7 commented Apr 4, 2024

which release has this fix ?

@djaym7
Copy link

djaym7 commented Apr 4, 2024

gradio_client@0.11.0 found it

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.

file upload failed using gradio_client.Client, when there is an auth
4 participants