Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,19 +6,30 @@ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-bas
|
|
| 6 |
|
| 7 |
# Função para transcrever o áudio
|
| 8 |
def transcribe(audio_file):
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Interface gráfica com Gradio
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
-
gr.Markdown("# Whisper Transcription")
|
|
|
|
| 15 |
with gr.Row():
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Vincular ação ao botão
|
| 21 |
transcribe_button.click(transcribe, inputs=[audio_input], outputs=[transcription_output])
|
| 22 |
|
| 23 |
# Rodar a aplicação
|
| 24 |
-
demo.launch()
|
|
|
|
| 6 |
|
| 7 |
# Função para transcrever o áudio
|
| 8 |
def transcribe(audio_file):
|
| 9 |
+
try:
|
| 10 |
+
# Habilitar timestamps para áudios longos
|
| 11 |
+
transcription = transcriber(audio_file, return_timestamps=True)["text"]
|
| 12 |
+
return transcription
|
| 13 |
+
except ValueError as e:
|
| 14 |
+
return f"Erro ao processar o áudio: {str(e)}"
|
| 15 |
|
| 16 |
# Interface gráfica com Gradio
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
+
gr.Markdown("# 🎙️ Whisper Transcription - Upload ou Grave Áudio")
|
| 19 |
+
|
| 20 |
with gr.Row():
|
| 21 |
+
with gr.Column(scale=1):
|
| 22 |
+
gr.Markdown("### 1️⃣ Envie ou grave seu áudio")
|
| 23 |
+
audio_input = gr.Audio(type="filepath", label="Envie um arquivo de áudio (máx. 1 min)")
|
| 24 |
+
|
| 25 |
+
with gr.Column(scale=1):
|
| 26 |
+
gr.Markdown("### 2️⃣ Resultado da transcrição")
|
| 27 |
+
transcription_output = gr.Textbox(label="Transcrição", lines=10, interactive=False)
|
| 28 |
+
|
| 29 |
+
transcribe_button = gr.Button("🚀 Transcrever")
|
| 30 |
|
| 31 |
# Vincular ação ao botão
|
| 32 |
transcribe_button.click(transcribe, inputs=[audio_input], outputs=[transcription_output])
|
| 33 |
|
| 34 |
# Rodar a aplicação
|
| 35 |
+
demo.launch(share=True)
|