import whisper import gradio as gr # Force the model to run on CPU device = "cpu" print("Running on CPU") # Load the tiny Whisper model 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 # Create the Gradio interface demo = gr.Interface( fn=transcribe, # The function to be called for transcription inputs=gr.Audio(type="filepath", label="Upload your audio file"), # Input audio field outputs=gr.Textbox(label="Transcription"), # Output transcription title="Whisper Speech-to-Text", # Title of the interface description="Record audio using your microphone and get a transcription using the Whisper model." ) # Launch the Gradio interface demo.launch()