-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Allow gradio embeds in colab without share #2455
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
Changes from 13 commits
3107ab9
352ca30
dc3930e
f9c0bee
861e610
7bc9ee6
9f51aa3
782a2a2
90ebf80
b9d945b
cca6af4
0c78d1b
d366385
aae670f
e0f74e4
384f37a
93cf890
6c341fb
7324d0d
f75b0a1
7da5ef2
4a26ff0
fd0dc55
4551e21
5bb670e
99204bd
8a8f12f
01f892f
a70c64e
0ca1f6f
a80a307
5047a67
b386769
fc37ca2
03e48d7
2146db4
7a13c82
8468da8
83793ea
17c6835
80217d0
d6c8896
abf30b4
1daa67f
28a0afa
87e4320
02a4c8b
2871509
b252da4
be28836
5aad65c
80b3a0e
84867d1
83946ee
7ca1819
b16d6b1
7e8bd26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -315,6 +315,8 @@ async def run_predict( | |
| ) | ||
| return output | ||
|
|
||
| @app.post("/run/{api_name}", dependencies=[Depends(login_check)]) | ||
|
aliabid94 marked this conversation as resolved.
|
||
| @app.post("/run/{api_name}/", dependencies=[Depends(login_check)]) | ||
| @app.post("/api/{api_name}", dependencies=[Depends(login_check)]) | ||
| @app.post("/api/{api_name}/", dependencies=[Depends(login_check)]) | ||
| async def predict( | ||
|
|
@@ -328,7 +330,7 @@ async def predict( | |
| if body.fn_index is None: | ||
| return JSONResponse( | ||
| content={ | ||
| "error": f"This app has no endpoint /api/{api_name}/." | ||
| "error": f"This app has no endpoint /run/{api_name}/." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we are migrating from "/api" to "/run" as the official API endpoint. Let's make sure to update the "view API" page as well. Also this is a bit of an edge case but what happens if a user-supplied
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does colab block any call with a substring "api"? Anyways, even if they create a custom named API, the frontend does not use the names API's, so gradio UI will still work fine. |
||
| }, | ||
| status_code=500, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <script> | ||
| document.querySelector("base").href = "https://localhost:$PORT"; | ||
|
|
||
| function rehydrate() { | ||
| for (const script of document.querySelectorAll("script")) { | ||
| const newScript = document.createElement('script') | ||
| newScript.type = script.type; | ||
| newScript.src = script.src; | ||
| newScript.textContent = script.textContent; | ||
| const head = document.getElementsByTagName('head')[0]; | ||
| if (script.textContent.includes("window.gradio_config =")) { | ||
| const config_re = /^\s*window.gradio_config\s*=\s*({[^]+})\s*;\s*$/; | ||
| window.gradio_config = JSON.parse(config_re.exec(script.textContent)[1]); | ||
| } | ||
| head.appendChild(newScript); | ||
| newScript.remove(); | ||
| } | ||
| } | ||
| fetch(".") | ||
| .then((x) => x.text()) | ||
| .then((html) => { | ||
| document.body.innerHTML = html; | ||
| }) | ||
| .then(() => rehydrate()).catch(() => { | ||
| document.body.innerHTML = `<h1 color="red">There was a problem running Gradio in colab, please rerun the block with gradio==3.5 and file an issue on GitHub if it doesn't not work.</h1>`; | ||
|
aliabid94 marked this conversation as resolved.
Outdated
|
||
| }); | ||
| </script> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 3.5 | ||
| 3.0.1b150 |
Uh oh!
There was an error while loading. Please reload this page.