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

Initialize the client with the fake host for Lite server #8935

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/flat-meals-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gradio/app": minor
"@gradio/wasm": minor
"gradio": minor
---

feat:Initialize the client with the fake host for Lite server
3 changes: 2 additions & 1 deletion js/app/src/lite/LiteIndex.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ErrorDisplay from "./ErrorDisplay.svelte";
import type { ThemeMode } from "../types";
import { WorkerProxy, type WorkerProxyOptions } from "@gradio/wasm";
import { FAKE_LITE_HOST } from "@gradio/wasm/network";
import { Client } from "@gradio/client";
import { wasm_proxied_fetch } from "./fetch";
import { wasm_proxied_stream_factory } from "./sse";
Expand Down Expand Up @@ -181,7 +182,7 @@
<Index
space={null}
src={null}
host={null}
host={FAKE_LITE_HOST}
Copy link
Member Author

Choose a reason for hiding this comment

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

This host is passed to the client object through the code below

api_url =
BUILD_MODE === "dev" || gradio_dev_mode === "dev"
? `http://localhost:${
typeof server_port === "number" ? server_port : 7860
}`
: host || space || src || location.origin;
app = await Client.connect(api_url, {
status_callback: handle_status,
with_null_state: true,
events: ["data", "log", "status", "render"]
});

and the client makes an HTTP call if the URL matches HF Spaces' host here, which causes the error:

const { http_protocol, host, space_id } = await process_endpoint(
this.app_reference,
this.options.hf_token
);

So we explicitly set the different value to host, which is also considered as a special host name representing the Lite's server.

Copy link
Member Author

Choose a reason for hiding this comment

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

@pngwn Should we use src rather than host? #3065

Copy link
Member

Choose a reason for hiding this comment

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

That is a breaking change, so it will need to happen in 5.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

@pngwn Thanks but do you mean we need to wait for this to be merged until 5.0, or just using host not src is ok and we can merge this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be merged after #9102?

{info}
{container}
{is_embed}
Expand Down
6 changes: 5 additions & 1 deletion js/wasm/network/host.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// A special hostname representing the Lite's server.
// For example, when the endpoint is a local file (`file:/*`), the host name is set to this value (ref: determine_protocol() in client/js/src/helpers/init_helpers.ts)
export const FAKE_LITE_HOST = "lite.local";

export function is_self_host(url: URL): boolean {
return (
url.host === window.location.host ||
url.host === "localhost:7860" ||
url.host === "127.0.0.1:7860" || // Ref: https://github.com/gradio-app/gradio/blob/v3.32.0/js/app/src/Index.svelte#L194
url.host === "lite.local" // A special hostname set when the endpoint is a local file (`file:/*`). See `determine_protocol()` in `client/js/src/utils.ts`
url.host === FAKE_LITE_HOST
);
}
Loading