import whisper | |
import gradio as gr | |
from transformers import pipeline | |
# Load models | |
def transcribe_audio(file_path): | |
model = whisper.load_model("base") # Use "tiny", "base", "small", etc. | |
result = model.transcribe(file_path) | |
return result["text"] | |
def extract_topics(text): | |
summarizer = pipeline("summarization") | |
summary = summarizer(text, max_length=50, min_length=25, do_sample=False) | |
return summary[0]["summary_text"] | |
def process_audio(file): | |
# Transcribe the audio file | |
transcript = transcribe_audio(file.name) | |
# Extract topics from the transcription | |
topics = extract_topics(transcript) | |
return transcript, topics | |
# Gradio interface | |
interface = gr.Interface( | |
fn=process_audio, | |
inputs=gr.Audio(source="upload", type="filepath"), | |
outputs=["text", "text"], | |
title="Audio Transcription and Topic Extraction", | |
description="Upload an audio file to get a transcription and extract main topics." | |
) | |
if __name__ == "__main__": | |
interface.launch() | |