Skip to content

Commit 6875d66

Browse files
Add Integrated Textbox to the docs + spaces (#343)
* Add to docs * Fix requirements
1 parent c97b188 commit 6875d66

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

demo/integrated_textbox/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Integrated Text Box
3+
emoji: 📝
4+
colorFrom: purple
5+
colorTo: red
6+
sdk: gradio
7+
sdk_version: 5.31.0
8+
app_file: app.py
9+
pinned: false
10+
license: mit
11+
short_description: Talk or type to ANY LLM!
12+
tags: [webrtc, websocket, gradio, secret|HF_TOKEN]
13+
---
14+
15+
# Integrated Textbox
16+
17+
Talk or type to ANY LLM!
18+
19+
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# /// script
22
# dependencies = [
3-
# "fastrtc[vad, stt]==0.0.26.rc1",
3+
# "fastrtc[vad, stt]">=0.0.26",
44
# "openai",
55
# ]
66
# ///
@@ -14,8 +14,10 @@
1414
WebRTC,
1515
WebRTCData,
1616
WebRTCError,
17+
get_hf_turn_credentials,
1718
get_stt_model,
1819
)
20+
from gradio.utils import get_space
1921
from openai import OpenAI
2022

2123
stt_model = get_stt_model()
@@ -118,9 +120,17 @@ def hide_token(provider: str):
118120
)
119121
provider.change(hide_token, inputs=[provider], outputs=[token])
120122
cb = gr.Chatbot(type="messages", height=600)
121-
webrtc = WebRTC(modality="audio", mode="send", variant="textbox")
123+
webrtc = WebRTC(
124+
modality="audio",
125+
mode="send",
126+
variant="textbox",
127+
rtc_configuration=get_hf_turn_credentials if get_space() else None,
128+
server_rtc_configuration=get_hf_turn_credentials(ttl=3_600 * 24 * 30)
129+
if get_space()
130+
else None,
131+
)
122132
webrtc.stream(
123-
ReplyOnPause(response),
133+
ReplyOnPause(response), # type: ignore
124134
inputs=[webrtc, cb, token, model, provider],
125135
outputs=[cb],
126136
concurrency_limit=100,
@@ -130,4 +140,4 @@ def hide_token(provider: str):
130140
)
131141

132142
if __name__ == "__main__":
133-
demo.launch(server_port=6980)
143+
demo.launch(server_port=7860)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastrtc[vad, stt]
2+
openai

docs/cookbook.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A collection of applications built with FastRTC. Click on the tags below to find
2323
<button class="tag-button" data-tag="audio"><code>Audio</code></button>
2424
<button class="tag-button" data-tag="video"><code>Video</code></button>
2525
<button class="tag-button" data-tag="llm"><code>LLM</code></button>
26+
<button class="tag-button" data-tag="text"><code>Text</code></button>
2627
<button class="tag-button" data-tag="computer-vision"><code>Computer Vision</code></button>
2728
<button class="tag-button" data-tag="real-time-api"><code>Real-time API</code></button>
2829
<button class="tag-button" data-tag="voice-chat"><code>Voice Chat</code></button>
@@ -74,6 +75,19 @@ document.querySelectorAll('.tag-button').forEach(button => {
7475

7576
[:octicons-code-16: Code](https://huggingface.co/spaces/fastrtc/talk-to-llama4/blob/main/app.py)
7677

78+
- :speaking_head:{ .lg .middle }:llama:{ .lg .middle } __Integrated Textbox__
79+
{: data-tags="audio,llm,text,voice-chat"}
80+
81+
---
82+
83+
Talk or type to any LLM with FastRTC's integrated audio + text textbox.
84+
85+
<video width=98% src="https://github.com/user-attachments/assets/35c982a1-4a58-4947-af89-7ff287070ef5" controls style="text-align: center"></video>
86+
87+
[:octicons-arrow-right-24: Demo](https://huggingface.co/spaces/fastrtc/integrated-textbox)
88+
89+
[:octicons-code-16: Code](https://huggingface.co/spaces/fastrtc/integrated-textbox/blob/main/app.py)
90+
7791
- :speaking_head:{ .lg .middle }:eyes:{ .lg .middle } __Gemini Audio Video Chat__
7892
{: data-tags="audio,video,real-time-api"}
7993

docs/userguide/gradio.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,24 @@ This is common for displaying a multimodal text/audio conversation in a Chatbot
9393
=== "Notes"
9494
1. Pass your data to `AdditionalOutputs` and yield it.
9595
2. In this case, no audio is being returned, so we set `mode="send"`. However, if we set `mode="send-receive"`, we could also yield generated audio and `AdditionalOutputs`.
96-
3. The `on_additional_outputs` event does not take `inputs`. It's common practice to not run this event on the queue since it is just a quick UI update.
96+
3. The `on_additional_outputs` event does not take `inputs`. It's common practice to not run this event on the queue since it is just a quick UI update.
97+
98+
99+
## Integrated Textbox
100+
101+
For audio usecases, you may want to allow your users to type or speak. You can set the `variant="textbox"` argument in the WebRTC component to place a Textbox with a microphone input in the UI. See the `Integrated Textbox` demo in the cookbook or in the `demo` directory of the github repository.
102+
103+
``` py
104+
webrtc = WebRTC(
105+
modality="audio",
106+
mode="send-receive",
107+
variant="textbox",
108+
)
109+
```
110+
111+
112+
!!! tip "Stream Class"
113+
To use the "textbox" variant via the `Stream` class, set it in the `UIArgs` class and pass it to the stream via the `ui_args` parameter.
114+
115+
116+
<video width=98% src="https://github.com/user-attachments/assets/35c982a1-4a58-4947-af89-7ff287070ef5" controls style="text-align: center"></video>

0 commit comments

Comments
 (0)