File size: 1,445 Bytes
0b3aba0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()