From cab4441e4119f495e8174a2707fd31816a34220e Mon Sep 17 00:00:00 2001 From: Freddy Boulton <41651716+freddyaboulton@users.noreply.github.com> Date: Mon, 28 Apr 2025 12:47:13 -0400 Subject: [PATCH 01/42] Commit --- demo/dia_dialogue_demo/app.py | 108 +++++ gradio/__init__.py | 2 + gradio/components/__init__.py | 2 + gradio/components/dialogue.py | 135 ++++++ gradio/stubs/anyio.pyi | 2 +- js/dialogue/Dialogue.svelte | 499 ++++++++++++++++++++++ js/dialogue/DropdownOptions.svelte | 165 +++++++ js/dialogue/Example.svelte | 19 + js/dialogue/Index.svelte | 96 +++++ js/dialogue/main.ts | 2 + js/dialogue/package.json | 42 ++ js/dialogue/utils.ts | 4 + js/dropdown/Index.svelte | 1 + js/dropdown/shared/DropdownOptions.svelte | 12 +- package.json | 1 + pnpm-lock.yaml | 28 ++ 16 files changed, 1115 insertions(+), 3 deletions(-) create mode 100644 demo/dia_dialogue_demo/app.py create mode 100644 gradio/components/dialogue.py create mode 100644 js/dialogue/Dialogue.svelte create mode 100644 js/dialogue/DropdownOptions.svelte create mode 100644 js/dialogue/Example.svelte create mode 100644 js/dialogue/Index.svelte create mode 100644 js/dialogue/main.ts create mode 100644 js/dialogue/package.json create mode 100644 js/dialogue/utils.ts diff --git a/demo/dia_dialogue_demo/app.py b/demo/dia_dialogue_demo/app.py new file mode 100644 index 0000000000..181aae15be --- /dev/null +++ b/demo/dia_dialogue_demo/app.py @@ -0,0 +1,108 @@ +import gradio as gr +import httpx + + +emotions = [ + "(laughs)", + "(clears throat)", + "(sighs)", + "(gasps)", + "(coughs)", + "(singing)", + "(sings)", + "(mumbles)", + "(beep)", + "(groans)", + "(sniffs)", + "(claps)", + "(screams)", + "(inhales)", + "(exhales)", + "(applause)", + "(burps)", + "(humming)", + "(sneezes)", + "(chuckle)", + "(whistles)", +] +speakers = ["Speaker 1", "Speaker 2"] + +client = httpx.AsyncClient(timeout=180) +API_URL = "https://router.huggingface.co/fal-ai/fal-ai/dia-tts" + + +async def query(dialogue: str, token: gr.OAuthToken | None): + if token is None: + raise gr.Error( + "No token provided. Use Sign in with Hugging Face to get a token." + ) + headers = { + "Authorization": f"Bearer {token.token}", + } + response = await client.post(API_URL, headers=headers, json={"text": dialogue}) + url = response.json()["audio"]["url"] + print("URL: ", url) + return url + + +def formatter(speaker, text): + speaker = speaker.split(" ")[1] + return f"[S{speaker}] {text}" + + +with gr.Blocks() as demo: + with gr.Sidebar(): + login_button = gr.LoginButton() + gr.HTML( + """ +
API Recorder
-API Recorder
+
- {api_count} API endpoint{#if api_count > 1}s{/if}
{api_count}
- Choose a language to see the code snippets for interacting with the - API. + Choose one of the following ways to interact with the API.
+ Available MCP Tools +
{name}
+ ({param.type})
+ + {param.description + ? param.description + : "⚠︎ No description for this parameter in function docstring"} +
+No parameters
+ {/if} ++ + Integration: To add this MCP to clients that + support SSE (e.g. Cursor, Windsurf, Cline), simply add the + following configuration to your MCP config: +
+
+
+
+
+
+ {JSON.stringify(
+ {
+ mcpServers: {
+ gradio: {
+ url: mcp_server_url
+ }
+ }
+ },
+ null,
+ 2
+ )}
+
+
+ + Experimental stdio support: For clients that only + support stdio, first + install Node.js. Then, you can use the following command: +
+
+
+
+
+
+ {JSON.stringify(
+ {
+ mcpServers: {
+ gradio: {
+ command: "npx",
+ arguments: ["mcp-remote", mcp_server_url]
+ }
+ }
+ },
+ null,
+ 2
+ )}
+
+
+ +
+ {:else} + This Gradio app can also serve as an MCP server, with an MCP + tool corresponding to each API endpoint. To enable this, launch + this Gradio app with
.launch(mcp_server=True)
or
+ set the GRADIO_MCP_SERVER
env variable to
+ "True"
.
+ {/if}
{:else}
1. Confirm that you have cURL installed on your system.
{/if}
-
- 2. Find the API endpoint below corresponding to your desired
- function in the app. Copy the code snippet, replacing the
- placeholder values with your own input data.
- {#if space_id}If this is a private Space, you may need to pass your
- Hugging Face token as well (read more).{/if}
-
- Or use the
-
- to automatically generate your API requests.
- {#if current_language == "bash"}
Making a
- prediction and getting a result requires
- 2 requests: a
- POST
- and a GET
request. The POST
request
- returns an EVENT_ID
, which is used in the second
- GET
request to fetch the results. In these snippets,
- we've used awk
and read
to parse the
- results, combining these two requests into one command for ease of
- use. {#if username !== null}
- Note: connecting to an authenticated app requires an additional
- request.{/if} See
- curl docs.
- {/if}
-
-
-
+ Use our Docs MCP +
+ {#if show_dropdown}