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

More fixes for gr.load() #7376

Closed
wants to merge 10 commits into from
Closed

More fixes for gr.load() #7376

wants to merge 10 commits into from

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Feb 9, 2024

So this is a partial fix to: #7362

This PR allows these two Spaces to be loaded at least. They won't work yet (will tackle that next)

import gradio as gr

gr.load("gradio/chatbot_multimodal", src="spaces").launch()

and partially fixes the first one:

import gradio as gr

gr.load("gradio/chatinterface_streaming_echo", src="spaces").launch()

These demos will load but if you try running them you'll get errors. As far as I can tell, this has to do with the fact that the logic for gathering/uploading files is incorrect. So I'll tackle that separately in #7360

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 9, 2024

🪼 branch checks and previews

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

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/ae372689f1e00f49323e9b1eea8cfbd4fb6c3b0a/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@ae372689f1e00f49323e9b1eea8cfbd4fb6c3b0a#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 9, 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.

More fixes for gr.load()

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.

@abidlabs abidlabs marked this pull request as ready for review February 9, 2024 20:48
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Looks good @abidlabs but had two questions/comments!

gradio/blocks.py Show resolved Hide resolved
client/python/gradio_client/client.py Show resolved Hide resolved
temp_file_path = processing_utils.save_file_to_cache(
url_or_file_path, cache_dir=self.GRADIO_CACHE
)
try:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes sense but I think we're not covering the case where the value of the component is a file on the space.

I loaded the following demo

gr.load("gradio/image_mod_default_image", src="spaces").launch()

And this is what I see

image

From the console

file-url.ts:12 Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL
    at should_proxy_wasm_src (file-url.ts:12:14)
    at resolve_wasm_src (file-url.ts:26:22)
    at $$self.$$.update (Image.svelte:28:3)
    at init (svelte.js:3246:5)
    at new Image (Image.svelte:30:21)
    at create_if_block (Example-9a0e0dba.js:29:10)
    at create_fragment (Example.svelte:19:39)
    at init (svelte.js:3250:34)
    at new Example (Example.svelte:8:29)
    at construct_svelte_component (svelte.js:1613:9)

and

GET http://127.0.0.1:7861/proxy=https://gradio-image-mod-default-image.hf.space/file=undefined 403 (Forbidden)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm okay I'll look at this more closely on Monday, thanks for catching this @freddyaboulton

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 actually can't repro this issue, the Space loads for me:

image

I do have an issue when actually trying to run the app, but that also will be tackled as part of #7360

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is related to #7360 actually.

The function server returns the right path but the issue is that the FileData object is wrapped in a list -

image

I think this may be because of the change to reduce_singleton_output?

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'll take a look!

@avfranco-br
Copy link

Hello @abidlabs,

I've gone through all the issues and installed the latest gradio and gradio-client libraries but still getting the same error while trying to load one space from another. Output below. Any advice? Thanks, Alexandre

Fetching Space from: https://huggingface.co/spaces/avfranco/ArchitectGPT
Loaded as API: https://avfranco-architectgpt.hf.space

{
"name": "KeyError",
"message": "None",
"stack": "---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[6], line 7
4 read_key = os.environ.get('HUGGINGFACEHUB_API_TOKEN', None)
6 ##with gr.Blocks() as demo:
----> 7 gr.load("avfranco/ArchitectGPT", hf_token=read_key, src="spaces").launch()
8 ##demo.launch(debug=True)

File ~/.pyenv/versions/3.11.3/envs/huggingface/lib/python3.11/site-packages/gradio/external.py:60, in load(name, src, hf_token, alias, **kwargs)
36 @document()
37 def load(
38 name: str,
(...)
42 **kwargs,
43 ) -> Blocks:
44 """
45 Constructs a demo from a Hugging Face repo. Can accept model repos (if src is "models") or Space repos (if src is "spaces"). The input
46 and output components are automatically loaded from the repo. Note that if a Space is loaded, certain high-level attributes of the Blocks (e.g.
(...)
58 demo.launch()
59 """
---> 60 return load_blocks_from_repo(
61 name=name, src=src, hf_token=hf_token, alias=alias, **kwargs
62 )

File ~/.pyenv/versions/3.11.3/envs/huggingface/lib/python3.11/site-packages/gradio/external.py:99, in load_blocks_from_repo(name, src, hf_token, alias, **kwargs)
94 warnings.warn(
95 """You are loading a model/Space with a different access token than the one you used to load a previous model/Space. This is not recommended, as it may cause unexpected behavior."""
96 )
97 Context.hf_token = hf_token
---> 99 blocks: gradio.Blocks = factory_methods[src](name, hf_token, alias, **kwargs)
100 return blocks

File ~/.pyenv/versions/3.11.3/envs/huggingface/lib/python3.11/site-packages/gradio/external.py:417, in from_spaces(space_name, hf_token, alias, **kwargs)
410 if kwargs:
411 warnings.warn(
412 "You cannot override parameters for this Space by passing in kwargs. "
413 "Instead, please load the Space as a function and use it to create a "
414 "Blocks or Interface locally. You may find this Guide helpful: "
415 "https://gradio.app/using_blocks_like_functions/\"
416 )
--> 417 return from_spaces_blocks(space=space_name, hf_token=hf_token)

File ~/.pyenv/versions/3.11.3/envs/huggingface/lib/python3.11/site-packages/gradio/external.py:440, in from_spaces_blocks(space, hf_token)
438 else:
439 predict_fns.append(None)
--> 440 return gradio.Blocks.from_config(client.config, predict_fns, client.src)

File ~/.pyenv/versions/3.11.3/envs/huggingface/lib/python3.11/site-packages/gradio/blocks.py:729, in Blocks.from_config(cls, config, fns, proxy_url)
727 _targets = dependency.pop("targets")
728 trigger = dependency.pop("trigger", None)
--> 729 targets = [
730 getattr(
731 original_mapping[
732 target if isinstance(target, int) else target[0]
733 ],
734 trigger if isinstance(target, int) else target[1],
735 )
736 for target in _targets
737 ]
738 dependency.pop("backend_fn")
739 dependency.pop("documentation", None)

File ~/.pyenv/versions/3.11.3/envs/huggingface/lib/python3.11/site-packages/gradio/blocks.py:731, in (.0)
727 _targets = dependency.pop("targets")
728 trigger = dependency.pop("trigger", None)
729 targets = [
730 getattr(
--> 731 original_mapping[
732 target if isinstance(target, int) else target[0]
733 ],
734 trigger if isinstance(target, int) else target[1],
735 )
736 for target in _targets
737 ]
738 dependency.pop("backend_fn")
739 dependency.pop("documentation", None)

KeyError: None"
}

@abidlabs
Copy link
Member Author

Hi @avfranco-br can you share a public Space with me?

@abidlabs abidlabs added the v: patch A change that requires a patch release label Feb 14, 2024
@abidlabs
Copy link
Member Author

Thanks for reviewing @freddyaboulton, I think this can be merged in as a partial fix for #7362

@avfranco-br
Copy link

Hi @avfranco-br can you share a public Space with me?

Thanks @abidlabs for your quick response. Sure, here it's ea4all_gpt.

@abidlabs
Copy link
Member Author

Thanks @avfranco-br yes so the error you're getting is the one that this PR should fix. If you'd like to try it, you can build Gradio from this PR in your Space.

I've opened a PR for your Space here: https://huggingface.co/spaces/avfranco/ea4all_gpt/discussions/1

@avfranco-br
Copy link

Thanks @abidlabs,

I've installed Gradio from both PRs below, but the error still persists. Shall I do something else?

@abidlabs abidlabs marked this pull request as draft February 15, 2024 20:56
@abidlabs
Copy link
Member Author

abidlabs commented Mar 1, 2024

Closing as I'll do this as part of #7575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants