mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-23 11:39:17 +08:00
Fix Loading SSR'd apps via gr.load (#9827)
* add code * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
458a38cabb
commit
7ed8d02979
5
.changeset/long-wolves-serve.md
Normal file
5
.changeset/long-wolves-serve.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Fix Loading SSR'd apps via gr.load
|
@ -426,7 +426,6 @@ def from_spaces(
|
||||
headers = {}
|
||||
if hf_token not in [False, None]:
|
||||
headers["Authorization"] = f"Bearer {hf_token}"
|
||||
|
||||
iframe_url = (
|
||||
httpx.get(
|
||||
f"https://huggingface.co/api/spaces/{space_name}/host", headers=headers
|
||||
@ -440,15 +439,23 @@ def from_spaces(
|
||||
f"Could not find Space: {space_name}. If it is a private or gated Space, please provide your Hugging Face access token (https://huggingface.co/settings/tokens) as the argument for the `hf_token` parameter."
|
||||
)
|
||||
|
||||
r = httpx.get(iframe_url, headers=headers)
|
||||
config_request = httpx.get(iframe_url + "/config", headers=headers)
|
||||
if config_request.status_code == 404:
|
||||
r = httpx.get(iframe_url, headers=headers)
|
||||
|
||||
result = re.search(
|
||||
r"window.gradio_config = (.*?);[\s]*</script>", r.text
|
||||
) # some basic regex to extract the config
|
||||
try:
|
||||
config = json.loads(result.group(1)) # type: ignore
|
||||
except AttributeError as ae:
|
||||
raise ValueError(f"Could not load the Space: {space_name}") from ae
|
||||
result = re.search(
|
||||
r"window.gradio_config = (.*?);[\s]*</script>", r.text
|
||||
) # some basic regex to extract the config
|
||||
try:
|
||||
config = json.loads(result.group(1)) # type: ignore
|
||||
except AttributeError as ae:
|
||||
raise ValueError(f"Could not load the Space: {space_name}") from ae
|
||||
elif config_request.status_code == 200:
|
||||
config = config_request.json()
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Could not load the Space: {space_name} because the config could not be fetched."
|
||||
)
|
||||
if "allow_flagging" in config: # Create an Interface for Gradio 2.x Spaces
|
||||
return from_spaces_interface(
|
||||
space_name, config, alias, hf_token, iframe_url, **kwargs
|
||||
|
Loading…
Reference in New Issue
Block a user