File size: 1,777 Bytes
0b3aba0
 
 
491d71f
 
0b3aba0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491d71f
 
 
 
 
 
0b3aba0
491d71f
 
 
0b3aba0
 
 
 
 
491d71f
0b3aba0
491d71f
7396b9d
0b3aba0
 
 
491d71f
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
44
45
import gradio as gr
import whisper
from transformers import pipeline
from gtts import gTTS
import os

# Load the Whisper model from openai-whisper
whisper_model = whisper.load_model("tiny")

# 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']

    # Step 3: Convert the summarized text into speech using the Hugging Face TTS model
    # Breakdown into multiple steps
    tts = gTTS(text=summary, lang='en')           # Generate the TTS output
    tts.save("summarized_audio.wav")

    # Save the TTS audio to a file (WAV format)


    # Return the path to the saved summarized audio file
    return "summarized_audio.wav"

# 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=gr.File(label="Download Summarized Audio"),  # Provide a downloadable summarized audio file
    title="Audio Summarizer",  # Interface title
    description="Upload an audio file, and this tool will summarize it and generate a downloadable audio summary." , # Interface description
    examples=[["Classification_and_Regression_in_Machine_Learning.mp3"]]
)

# Launch the Gradio interface
interface.launch(debug=True)