text stringlengths 0 2k | heading1 stringlengths 3 79 | source_page_url stringclasses 188
values | source_page_title stringclasses 188
values |
|---|---|---|---|
We'll download the YOLOv10 model from the Hugging Face hub and instantiate a custom inference class to use this model.
The implementation of the inference class isn't covered in this guide, but you can find the source code [here](https://huggingface.co/spaces/freddyaboulton/webrtc-yolov10n/blob/main/inference.pyL9) i... | The Inference Function | https://gradio.app/guides/object-detection-from-webcam-with-webrtc | Streaming - Object Detection From Webcam With Webrtc Guide |
The Gradio demo is straightforward, but we'll implement a few specific features:
1. Use the `WebRTC` custom component to ensure input and output are sent to/from the server with WebRTC.
2. The [WebRTC](https://github.com/freddyaboulton/gradio-webrtc) component will serve as both an input and output component.
3. Util... | The Gradio Demo | https://gradio.app/guides/object-detection-from-webcam-with-webrtc | Streaming - Object Detection From Webcam With Webrtc Guide |
Our app is hosted on Hugging Face Spaces [here](https://huggingface.co/spaces/freddyaboulton/webrtc-yolov10n).
You can use this app as a starting point to build real-time image applications with Gradio. Don't hesitate to open issues in the space or in the [FastRTC GitHub repo](https://github.com/gradio-app/fastrtc) i... | Conclusion | https://gradio.app/guides/object-detection-from-webcam-with-webrtc | Streaming - Object Detection From Webcam With Webrtc Guide |
Modern voice applications should feel natural and responsive, moving beyond the traditional "click-to-record" pattern. By combining Groq's fast inference capabilities with automatic speech detection, we can create a more intuitive interaction model where users can simply start talking whenever they want to engage with ... | Introduction | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
Many voice apps currently work by the user clicking record, speaking, then stopping the recording. While this can be a powerful demo, the most natural mode of interaction with voice requires the app to dynamically detect when the user is speaking, so they can talk back and forth without having to continually click a re... | Background | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
- **Gradio**: Provides the web interface and audio handling capabilities
- **@ricky0123/vad-web**: Handles voice activity detection
- **Groq**: Powers fast LLM inference for natural conversations
- **Whisper**: Transcribes speech to text
Setting Up the Environment
First, let’s install and import our essential librari... | Key Components | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
e’ll create a function to transcribe the user’s audio input into text using Whisper, a powerful transcription model hosted on Groq. This transcription will also help us determine whether there’s meaningful speech in the input. Here’s how:
```python
def transcribe_audio(client, file_name):
if file_name is None:
... | Key Components | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
ext.strip()
return None
```
We also need to interpret the audio data response. The process_whisper_response function takes the resulting completion from Whisper and checks if the audio was just background noise or had actual speaking that was transcribed. It uses a threshold of 0.7 to interpret the no_speech_... | Key Components | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
ly detect when someone starts or stops speaking. Here’s how to implement it using ONNX in JavaScript:
```javascript
async function main() {
const script1 = document.createElement("script");
script1.src = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.14.0/dist/ort.js";
document.head.appendChild(script1)
const... | Key Components | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
",
streaming=False,
waveform_options=gr.WaveformOptions(waveform_color="B83A4B"),
)
with gr.Row():
chatbot = gr.Chatbot(label="Conversation")
state = gr.State(value=AppState())
demo.launch(theme=theme, js=js)
```
In this code block, we’re using Gradio’s `Blocks` API to c... | Key Components | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
1. When you open the app, the VAD system automatically initializes and starts listening for speech
2. As soon as you start talking, it triggers the recording automatically
3. When you stop speaking, the recording ends and:
- The audio is transcribed using Whisper
- The transcribed text is sent to the LLM
- The... | Summary | https://gradio.app/guides/automatic-voice-detection | Streaming - Automatic Voice Detection Guide |
Gradio includes more than 30 pre-built components (as well as many [community-built _custom components_](https://www.gradio.app/custom-components/gallery)) that can be used as inputs or outputs in your demo. These components correspond to common data types in machine learning and data science, e.g. the `gr.Image` compo... | Gradio Components | https://gradio.app/guides/the-interface-class | Building Interfaces - The Interface Class Guide |
We used the default versions of the `gr.Textbox` and `gr.Slider`, but what if you want to change how the UI components look or behave?
Let's say you want to customize the slider to have values from 1 to 10, with a default of 2. And you wanted to customize the output text field — you want it to be larger and have a lab... | Components Attributes | https://gradio.app/guides/the-interface-class | Building Interfaces - The Interface Class Guide |
Suppose you had a more complex function, with multiple outputs as well. In the example below, we define a function that takes a string, boolean, and number, and returns a string and number.
$code_hello_world_3
$demo_hello_world_3
Just as each component in the `inputs` list corresponds to one of the parameters of the... | Multiple Input and Output Components | https://gradio.app/guides/the-interface-class | Building Interfaces - The Interface Class Guide |
Gradio supports many types of components, such as `Image`, `DataFrame`, `Video`, or `Label`. Let's try an image-to-image function to get a feel for these!
$code_sepia_filter
$demo_sepia_filter
When using the `Image` component as input, your function will receive a NumPy array with the shape `(height, width, 3)`, wher... | An Image Example | https://gradio.app/guides/the-interface-class | Building Interfaces - The Interface Class Guide |
You can provide example data that a user can easily load into `Interface`. This can be helpful to demonstrate the types of inputs the model expects, as well as to provide a way to explore your dataset in conjunction with your model. To load example data, you can provide a **nested list** to the `examples=` keyword argu... | Example Inputs | https://gradio.app/guides/the-interface-class | Building Interfaces - The Interface Class Guide |
In the previous example, you may have noticed the `title=` and `description=` keyword arguments in the `Interface` constructor that helps users understand your app.
There are three arguments in the `Interface` constructor to specify where this content should go:
- `title`: which accepts text and can display it at the... | Descriptive Content | https://gradio.app/guides/the-interface-class | Building Interfaces - The Interface Class Guide |
If your prediction function takes many inputs, you may want to hide some of them within a collapsed accordion to avoid cluttering the UI. The `Interface` class takes an `additional_inputs` argument which is similar to `inputs` but any input components included here are not visible by default. The user must click on the... | Additional Inputs within an Accordion | https://gradio.app/guides/the-interface-class | Building Interfaces - The Interface Class Guide |
To create a demo that has both the input and the output components, you simply need to set the values of the `inputs` and `outputs` parameter in `Interface()`. Here's an example demo of a simple image filter:
$code_sepia_filter
$demo_sepia_filter
| Standard demos | https://gradio.app/guides/four-kinds-of-interfaces | Building Interfaces - Four Kinds Of Interfaces Guide |
What about demos that only contain outputs? In order to build such a demo, you simply set the value of the `inputs` parameter in `Interface()` to `None`. Here's an example demo of a mock image generation model:
$code_fake_gan_no_input
$demo_fake_gan_no_input
| Output-only demos | https://gradio.app/guides/four-kinds-of-interfaces | Building Interfaces - Four Kinds Of Interfaces Guide |
Similarly, to create a demo that only contains inputs, set the value of `outputs` parameter in `Interface()` to be `None`. Here's an example demo that saves any uploaded image to disk:
$code_save_file_no_output
$demo_save_file_no_output
| Input-only demos | https://gradio.app/guides/four-kinds-of-interfaces | Building Interfaces - Four Kinds Of Interfaces Guide |
A demo that has a single component as both the input and the output. It can simply be created by setting the values of the `inputs` and `outputs` parameter as the same component. Here's an example demo of a text generation model:
$code_unified_demo_text_generation
$demo_unified_demo_text_generation
It may be the case... | Unified demos | https://gradio.app/guides/four-kinds-of-interfaces | Building Interfaces - Four Kinds Of Interfaces Guide |
You can make interfaces automatically refresh by setting `live=True` in the interface. Now the interface will recalculate as soon as the user input changes.
$code_calculator_live
$demo_calculator_live
Note there is no submit button, because the interface resubmits automatically on change.
| Live Interfaces | https://gradio.app/guides/reactive-interfaces | Building Interfaces - Reactive Interfaces Guide |
Some components have a "streaming" mode, such as `Audio` component in microphone mode, or the `Image` component in webcam mode. Streaming means data is sent continuously to the backend and the `Interface` function is continuously being rerun.
The difference between `gr.Audio(source='microphone')` and `gr.Audio(source=... | Streaming Components | https://gradio.app/guides/reactive-interfaces | Building Interfaces - Reactive Interfaces Guide |
Adding examples to an Interface is as easy as providing a list of lists to the `examples`
keyword argument.
Each sublist is a data sample, where each element corresponds to an input of the prediction function.
The inputs must be ordered in the same order as the prediction function expects them.
If your interface only ... | Providing Examples | https://gradio.app/guides/more-on-examples | Building Interfaces - More On Examples Guide |
You may wish to provide some cached examples of your model for users to quickly try out, in case your model takes a while to run normally.
If `cache_examples=True`, your Gradio app will run all of the examples and save the outputs when you call the `launch()` method. This data will be saved in a directory called `gradi... | Caching examples | https://gradio.app/guides/more-on-examples | Building Interfaces - More On Examples Guide |
If the state is something that should be accessible to all function calls and all users, you can create a variable outside the function call and access it inside the function. For example, you may load a large model outside the function and use it inside the function so that every function call does not need to reload ... | Global State | https://gradio.app/guides/interface-state | Building Interfaces - Interface State Guide |
Another type of data persistence Gradio supports is session state, where data persists across multiple submits within a page session. However, data is _not_ shared between different users of your model. To store data in a session state, you need to do three things:
1. Pass in an extra parameter into your function, whi... | Session State | https://gradio.app/guides/interface-state | Building Interfaces - Interface State Guide |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.