Spaces:
Runtime error
Runtime error
import gradio as gr | |
import whisper | |
from transformers import pipeline | |
import torch | |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
# Load the Whisper model from openai-whisper | |
whisper_model = whisper.load_model("tiny") | |
whisper_model=whisper_model.to(device) | |
# Load the summarization model from Hugging Face | |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
def summarize_audio(audio_path): | |
# Step 1: Transcribe the uploaded audio file using Whisper | |
transcription_result = whisper_model.transcribe(audio_path) | |
transcription = transcription_result["text"] | |
# Step 2: Summarize the transcribed text using a pre-trained summarization model | |
summary = summarizer(transcription, max_length=50, min_length=25, do_sample=False)[0]['summary_text'] | |
return summary | |
# Gradio interface | |
interface = gr.Interface( | |
fn=summarize_audio, # The function to process the audio and return summarized audio | |
inputs=gr.Audio(type="filepath", label="Upload your audio file"), # Accept audio file uploads, file path as input | |
#outputs="text", # Provide a downloadable summarized audio file | |
outputs=gr.Textbox(label="summarized audio file"), | |
title="Audio Summarizer", # Interface title | |
description="Upload an audio file, and this tool will summarize it.", # Interface description | |
examples=[["audio_sample1.mp3"]] | |
) | |
# Launch the Gradio interface | |
interface.launch() | |