Spaces:
Running
on
Zero
Running
on
Zero
File size: 6,294 Bytes
6f63a5e 6f340af 6f63a5e 13fccc4 6f63a5e 6f340af 6f63a5e c7e5b6a 6f63a5e 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 13fccc4 6f340af 6f63a5e 6f340af |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
import gradio as gr
import os
def build_interface():
"""
Builds an enhanced Gradio interface for Bambara speech recognition.
"""
example_files = get_example_files()
custom_css = """
.gr-button-primary {
background-color: #2c5282 !important;
color: white !important;
border-radius: 8px !important;
font-weight: bold !important;
}
.gr-button-secondary {
background-color: #e2e8f0 !important;
color: #2d3748 !important;
border-radius: 8px !important;
}
.example-container {
background-color: #f7fafc;
padding: 16px;
border-radius: 8px;
margin-top: 16px;
}
.gr-textbox {
border-radius: 8px !important;
border: 1px solid #cbd5e0 !important;
}
.gr-audio {
border-radius: 8px !important;
}
.header {
text-align: center;
color: #2d3748;
}
.info-section {
background-color: #edf2f7;
padding: 16px;
border-radius: 8px;
margin-top: 16px;
}
"""
with gr.Blocks(title="Bambara Speech Recognition", css=custom_css) as demo:
# Header
gr.Markdown(
"""
<h1 class="header">π€ Bambara Speech Recognition</h1>
<p style="text-align: center; color: #4a5568;">
Powered by <b>MALIBA-AI</b> | Convert Bambara speech to text effortlessly
</p>
"""
)
# Main interaction section
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### ποΈ Record or Upload Audio")
audio_input = gr.Audio(
label="Record or Upload Audio",
type="filepath",
sources=["microphone", "upload"],
show_label=False
)
audio_preview = gr.Audio(
label="Preview Your Audio",
interactive=False,
visible=False
)
with gr.Row():
transcribe_btn = gr.Button(
"π Transcribe Audio",
variant="primary",
size="lg"
)
clear_btn = gr.Button(
"ποΈ Clear",
variant="secondary",
size="lg"
)
with gr.Column(scale=1):
gr.Markdown("### π Transcription Output")
output_text = gr.Textbox(
label="Transcribed Text (Bambara)",
lines=6,
placeholder="Your transcribed Bambara text will appear here...",
interactive=False,
show_copy_button=True
)
status_message = gr.Markdown(
value="",
visible=False
)
# Example audio section
if example_files:
gr.Markdown("## π΅ Try Example Audio Files")
with gr.Group(elem_classes="example-container"):
gr.Markdown(
"""
Listen to these sample Bambara audio files and transcribe them with one click.
"""
)
for idx, file in enumerate(example_files):
with gr.Row():
gr.Audio(
value=file,
label=f"Example {idx + 1}: {os.path.basename(file)}",
interactive=False,
show_label=True
)
gr.Button(
f"Transcribe Example {idx + 1}",
variant="primary",
size="sm"
).click(
fn=transcribe_audio,
inputs=gr.State(value=file),
outputs=[output_text, status_message],
show_progress=True,
_js="() => {return {show_progress: true}}"
)
gr.Markdown(
"""
<div class="info-section">
## βΉοΈ How to Use
1. **Record**: Click the microphone to speak in Bambara.
2. **Upload**: Select an audio file (WAV, MP3, M4A, FLAC, OGG).
3. **Transcribe**: Click "Transcribe Audio" or try an example.
4. **View**: See the transcribed text in Bambara.
## π Model Details
- **Model**: [sudoping01/maliba-asr-v1](https://huggingface.co/sudoping01/maliba-asr-v1)
- **Language**: Bambara (bm)
- **Sample Rate**: 16kHz (auto-resampled)
- **Best for**: Clear speech with minimal background noise
</div>
"""
)
def update_audio_preview(audio_file):
return gr.update(value=audio_file, visible=True), ""
def clear_inputs():
return None, "", gr.update(visible=False), ""
def transcribe_with_status(audio_file):
if not audio_file:
return "", "**Error**: Please provide an audio file."
result = transcribe_audio(audio_file)
if "Error" in result:
return result, f"**Error**: {result}"
return result, "**Success**: Transcription completed!"
audio_input.change(
fn=update_audio_preview,
inputs=audio_input,
outputs=[audio_preview, status_message]
).then(
fn=transcribe_with_status,
inputs=audio_input,
outputs=[output_text, status_message],
show_progress=True
)
transcribe_btn.click(
fn=transcribe_with_status,
inputs=audio_input,
outputs=[output_text, status_message],
show_progress=True
)
clear_btn.click(
fn=clear_inputs,
outputs=[audio_input, output_text, audio_preview, status_message]
)
return demo |