|
|
|
import whisper |
|
import gradio as gr |
|
|
|
|
|
from transformers import pipeline |
|
|
|
|
|
device = "cpu" |
|
print("Running on CPU") |
|
|
|
|
|
|
|
whisper_model = whisper.load_model("tiny") |
|
|
|
|
|
summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn") |
|
|
|
|
|
def transcribe_and_summarize(audio): |
|
|
|
transcription_result = whisper_model.transcribe(audio) |
|
transcription = transcription_result['text'] |
|
|
|
|
|
summary = summarizer(transcription, min_length=50, max_length=1000) |
|
summary_text = summary[0]['summary_text'] |
|
|
|
return transcription, summary_text |
|
|
|
|
|
demo = gr.Interface( |
|
fn=transcribe_and_summarize, |
|
inputs=gr.Audio(type="filepath", label="Upload your audio file"), |
|
outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")], |
|
title="Whisper Tiny Transcription and Summarization", |
|
examples=["Classification and Regression in Machine Learning.mp3"], |
|
description="Upload an audio file, get the transcription from Whisper tiny model and the summarized version using Hugging Face." |
|
) |
|
|
|
|
|
demo.launch(debug=True) |
|
|
|
|