Skip to content

Commit

Permalink
Replace Gradio deprecated methods in 3.mdx
Browse files Browse the repository at this point in the history
Replace the deprecated methods by those in Gradio 5.13.2:

1. `gr.Textbox(type="number")` --> `gr.Number()`.
2. `gr.Audio` covers both microphone and file upload without specifying `source`.
  • Loading branch information
renweizhukov authored Jan 29, 2025
1 parent 013f293 commit 666ffe3
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions chapters/en/chapter9/3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ gr.Interface(
[
gr.Dropdown(notes, type="index"),
gr.Slider(minimum=4, maximum=6, step=1),
gr.Textbox(type="number", value=1, label="Duration in seconds"),
gr.Number(value=1, label="Duration in seconds"),
],
"audio",
).launch()
Expand Down Expand Up @@ -153,23 +153,14 @@ import gradio as gr
model = pipeline("automatic-speech-recognition")


def transcribe_audio(mic=None, file=None):
if mic is not None:
audio = mic
elif file is not None:
audio = file
else:
return "You must either provide a mic recording or a file"
def transcribe_audio(audio):
transcription = model(audio)["text"]
return transcription


gr.Interface(
fn=transcribe_audio,
inputs=[
gr.Audio(source="microphone", type="filepath", optional=True),
gr.Audio(source="upload", type="filepath", optional=True),
],
inputs=gr.Audio(type="filepath"),
outputs="text",
).launch()
```
Expand All @@ -183,4 +174,4 @@ That's it! You can now use this interface to transcribe audio. Notice here that
by passing in the `optional` parameter as `True`, we allow the user to either
provide a microphone or an audio file (or neither, but that will return an error message).

Keep going to see how to share your interface with others!
Keep going to see how to share your interface with others!

0 comments on commit 666ffe3

Please sign in to comment.