Python library for easily interacting with trained machine learning models
Project description
tags: [gradio-custom-component, ] title: gradio_dialogue short_description: A gradio custom component colorFrom: blue colorTo: yellow sdk: gradio pinned: false app_file: space.py
gradio_dialogue
Python library for easily interacting with trained machine learning models
Installation
pip install gradio_dialogue
Usage
import gradio as gr
import httpx
from gradio_dialogue import Dialogue
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)
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."
)
API_URL = "https://router.huggingface.co/fal-ai/fal-ai/dia-tts"
headers = {
"Authorization": f"Bearer {token.token}",
}
response = await client.post(API_URL, headers=headers, json={"text": dialogue})
url = response.json()["audio"]["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(
"""
<h2 style='text-align: center; display: flex; align-items: center; justify-content: center;'>Model by <a href="https://huggingface.co/nari-labs/Dia-1.6B"> Nari Labs</a>. Powered by HF and <a href="https://fal.ai/">Fal AI</a> API.</h2>
<h3>Dia is a dialogue generation model that can generate realistic dialogue between two speakers. Use the dialogue component to create a conversation and then hit the submit button in the bottom right corner to see it come to life .</h3>
"""
)
with gr.Row():
with gr.Column():
dialogue = Dialogue(
speakers=speakers, emotions=emotions, formatter=formatter
)
with gr.Column():
with gr.Row():
audio = gr.Audio(label="Audio")
with gr.Row():
gr.DeepLinkButton(value="Share Audio via Link")
with gr.Row():
gr.Examples(
examples=[
[
[
{
"speaker": "Speaker 1",
"text": "I am a little tired today (sighs).",
},
{"speaker": "Speaker 2", "text": "Hang in there!"},
]
],
],
inputs=[dialogue],
cache_examples=False,
)
dialogue.submit(query, [dialogue], audio)
demo.launch(ssr_mode=False)
Dialogue
Initialization
| name | type | default | description |
|---|---|---|---|
value |
Any
|
None |
None |
label |
str | None
|
None |
None |
info |
str | None
|
None |
None |
show_label |
bool | None
|
None |
None |
container |
bool
|
True |
None |
scale |
int | None
|
None |
None |
min_width |
int | None
|
None |
None |
interactive |
bool | None
|
None |
None |
visible |
bool
|
True |
None |
elem_id |
str | None
|
None |
None |
elem_classes |
list[str] | str | None
|
None |
None |
render |
bool
|
True |
None |
key |
int | str | None
|
None |
None |
load_fn |
Callable | None
|
None |
None |
every |
Timer | float | None
|
None |
None |
inputs |
Component | Sequence[Component] | set[Component] | None
|
None |
None |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gradio_dialogue-0.0.5-py3-none-any.whl.
File metadata
- Download URL: gradio_dialogue-0.0.5-py3-none-any.whl
- Upload date:
- Size: 1.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
283fb1861dfc6248aa529232f58d4b061e5424068111dcc670bab860fffaa113
|
|
| MD5 |
0f116909263f3c41f5f315440f640e1f
|
|
| BLAKE2b-256 |
d7cbf157d8e179120e43f0942194719df22274b67323e3481c5197e1a8220aca
|