whisper_wrapper / app.py
Madhuslista's picture
Feature: Add file download link
68d07e5
raw
history blame
2.59 kB
#!/usr/bin/python
# -*- coding: utf-8 -*-
import gradio as gr
from lib.config import (
AUDIO_DIR,
TRANSCRIPTS_DIR,
)
from lib.media import (
extract_audio_from_video,
save_file,
)
from lib.model import (
transcribe_audio,
)
# -->> Tunables <<---------------------
# -->> Definitions <<------------------
def interface_creation():
with gr.Blocks() as interface:
with gr.Row():
with gr.Column():
gr.Markdown("## Extract Audio from Video")
audio_inp = [
gr.Video(label="Upload Video"),
gr.Textbox(value=AUDIO_DIR, label="Output Audio Folder Path"),
]
audio_btn = gr.Button("Extract Audio")
with gr.Column():
gr.Markdown("### Extracted Audio from Video")
audio_out = [
gr.Audio(label="Extracted Audio"),
gr.Textbox(label="Audio Path"),
]
with gr.Row():
with gr.Column():
gr.Markdown("## Transcribe Audio")
transcribe_inp = [
gr.Audio(label="Upload Audio"),
gr.Textbox(label="Audio Path"),
gr.Textbox(
value=TRANSCRIPTS_DIR, label="Output Transcript Folder Path"
),
]
transcribe_btn = gr.Button("Transcribe Audio")
with gr.Column():
gr.Markdown("### Transcription:")
transcribe_out = gr.Textbox(label="Transcription")
download_btn = gr.Button("Download Transcript")
download_path = gr.Textbox(label="Download File Path")
download_link = gr.Textbox(label="Download Link")
audio_btn.click(
fn=extract_audio_from_video, inputs=audio_inp, outputs=audio_out
).then(
fn=lambda audio_file, audio_path: [audio_file, audio_path],
inputs=audio_out,
outputs=[transcribe_inp[0], transcribe_inp[1]],
)
transcribe_btn.click(
transcribe_audio, inputs=transcribe_inp, outputs=transcribe_out
)
download_btn.click(
save_file,
inputs=[transcribe_inp[1], transcribe_inp[2], transcribe_out],
outputs=[download_path, download_link]
)
return interface
# -->> API <<--------------------------
iface = interface_creation()
iface.launch()
# -->> Execute <<----------------------
# -->> Export <<-----------------------