pritamdeka's picture
Update app.py
d9cee8f verified
raw
history blame
1.19 kB
import gradio as gr
import whisper
import os
# Load Whisper model
model = whisper.load_model("base")
# Function to transcribe audio file using Whisper
def transcribe_audio(audio_file):
# Check if the audio file exists and print the file path for debugging
if audio_file is None:
return "No audio file provided."
# Debugging: Print the file path to check if Gradio passes the file path correctly
print(f"Audio file path: {audio_file}")
if not os.path.exists(audio_file):
return "The audio file does not exist or is inaccessible."
# Load and transcribe the audio file
result = model.transcribe(audio_file)
transcription = result['text']
return transcription
# Gradio interface for transcription
iface = gr.Interface(
fn=transcribe_audio, # Function to process audio file
inputs=gr.Audio(type="filepath"), # Audio upload, pass file path
outputs="text", # Output the transcription as text
title="Whisper Audio Transcription",
description="Upload an audio file and get the transcription."
)
# Launch the Gradio interface with a shareable link (required for Colab)
iface.launch(share=True)