fix embed protocol (#2571)

* fix embed protocol

* changelog

* version

* Commit from GitHub Actions (Upload Python Package)

* version

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: GH ACTIONS <abidlabs@users.noreply.github.com>
This commit is contained in:
pngwn 2022-10-31 19:08:45 +00:00 committed by GitHub
parent 36e383a9f0
commit 17cd9b59bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 17 deletions

View File

@ -1,9 +1,33 @@
# Upcoming Release
## New Features:
No changes to highlight.
## Bug Fixes:
No changes to highlight.
## Documentation Changes:
No changes to highlight.
## Testing and Infrastructure Changes:
No changes to highlight.
## Breaking Changes:
No changes to highlight.
## Full Changelog:
No changes to highlight.
## Contributors Shoutout:
No changes to highlight.
# Version 3.8.1de# Version 1
## Bug Fixes:
* Ensure gradio apps embedded via spaces use the correct endpoint for predictions. [@pngwn](https://github.com/pngwn) in [PR 2567](https://github.com/gradio-app/gradio/pull/2567)
* Ensure gradio apps embedded via spaces use the correct websocket protocol. [@pngwn](https://github.com/pngwn) in [PR 2571](https://github.com/gradio-app/gradio/pull/2571)
## New Features:

View File

@ -1 +1 @@
3.8.1
3.8.2

View File

@ -119,21 +119,22 @@ export const fn =
function send_message(fn: number, data: any) {
ws_map.get(fn)?.send(JSON.stringify(data));
}
var ws_endpoint = is_embed
? new URL(api_endpoint).host
: api_endpoint === "api/"
? location.href
: api_endpoint;
var ws_protocol = ws_endpoint.startsWith("https") ? "wss:" : "ws:";
var ws_path =
is_embed || location.pathname === "/" ? "/" : location.pathname;
var ws_host =
BUILD_MODE === "dev" || location.origin === "http://localhost:3000"
? BACKEND_URL.replace("http://", "").slice(0, -1)
: is_embed
? new URL(api_endpoint).host
: location.host;
const WS_ENDPOINT = `${ws_protocol}//${ws_host}${ws_path}queue/join`;
let WS_ENDPOINT = "";
if (is_embed) {
WS_ENDPOINT = `wss://${new URL(api_endpoint).host}/queue/join`;
} else {
var ws_endpoint =
api_endpoint === "api/" ? location.href : api_endpoint;
var ws_protocol = ws_endpoint.startsWith("https") ? "wss:" : "ws:";
var ws_path = location.pathname === "/" ? "/" : location.pathname;
var ws_host =
BUILD_MODE === "dev" || location.origin === "http://localhost:3000"
? BACKEND_URL.replace("http://", "").slice(0, -1)
: location.host;
WS_ENDPOINT = `${ws_protocol}//${ws_host}${ws_path}queue/join`;
}
var websocket = new WebSocket(WS_ENDPOINT);
ws_map.set(fn_index, websocket);