Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
"""Q_A_Whisper_summarize.ipynb | |
Automatically generated by Colab. | |
Original file is located at | |
https://colab.research.google.com/drive/1uchqsFgN6JyJX5rYfyMy3H__ThfIRGXJ | |
**Question:** | |
"How can you create a Gradio app that allows users to upload an audio file, transcribe it using the Whisper tiny model, and then summarize the transcription using Hugging Face's BART summarization model?" | |
This question prompts the user to build the Gradio app using both Whisper for transcription and the BART model for summarization. | |
 | |
""" | |
!pip install gradio | |
!pip install git+https://github.com/openai/whisper.git | |
!pip install transformers | |
import gradio as gr | |
import whisper | |
from transformers import pipeline | |
# Load the tiny Whisper model | |
whisper_model = whisper.load_model("tiny") | |
model = whisper.load_model("base") | |
# Load the text summarization model from Hugging Face | |
summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn") | |
# Function to transcribe and summarize the audio file | |
def transcribe_and_summarize(audio): | |
# Step 1: Transcribe the audio using Whisper | |
transcription_result = whisper_model.transcribe(audio) | |
transcription = transcription_result['text'] | |
# Step 2: Summarize the transcription | |
summary = summarizer(transcription, min_length=10, max_length=100) | |
summary_text = summary[0]['summary_text'] | |
return transcription, summary_text | |
# Define the Gradio interface | |
interface = gr.Interface( | |
fn=transcribe_and_summarize, # Function to run | |
inputs=gr.Audio(type="filepath", label="Upload your audio file"), # Input audio field | |
outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")], # Output fields | |
title="Whisper Tiny Transcription and Summarization", | |
description="Upload an audio file, get the transcription from Whisper tiny model and the summarized version using Hugging Face." | |
) | |
# Launch the Gradio app | |
interface.launch(debug=True) |