Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import whisper
|
| 3 |
from transformers import pipeline
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 7 |
|
| 8 |
# Load the Whisper model from openai-whisper
|
| 9 |
whisper_model = whisper.load_model("tiny")
|
| 10 |
-
whisper_model=whisper_model.to(device)
|
| 11 |
|
| 12 |
# Load the summarization model from Hugging Face
|
| 13 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 14 |
|
| 15 |
|
| 16 |
-
|
| 17 |
def summarize_audio(audio_path):
|
| 18 |
# Step 1: Transcribe the uploaded audio file using Whisper
|
| 19 |
transcription_result = whisper_model.transcribe(audio_path)
|
|
@@ -22,21 +19,26 @@ def summarize_audio(audio_path):
|
|
| 22 |
# Step 2: Summarize the transcribed text using a pre-trained summarization model
|
| 23 |
summary = summarizer(transcription, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Gradio interface
|
| 29 |
interface = gr.Interface(
|
| 30 |
fn=summarize_audio, # The function to process the audio and return summarized audio
|
| 31 |
inputs=gr.Audio(type="filepath", label="Upload your audio file"), # Accept audio file uploads, file path as input
|
| 32 |
-
|
| 33 |
-
outputs=gr.Textbox(label="summarized audio file"),
|
| 34 |
title="Audio Summarizer", # Interface title
|
| 35 |
-
description="Upload an audio file, and this tool will summarize it.",
|
| 36 |
examples=[["audio_sample1.mp3"]]
|
| 37 |
-
|
| 38 |
-
|
| 39 |
)
|
| 40 |
|
| 41 |
# Launch the Gradio interface
|
| 42 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import whisper
|
| 3 |
from transformers import pipeline
|
| 4 |
+
from gtts import gTTS
|
| 5 |
+
import os
|
|
|
|
| 6 |
|
| 7 |
# Load the Whisper model from openai-whisper
|
| 8 |
whisper_model = whisper.load_model("tiny")
|
|
|
|
| 9 |
|
| 10 |
# Load the summarization model from Hugging Face
|
| 11 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 12 |
|
| 13 |
|
|
|
|
| 14 |
def summarize_audio(audio_path):
|
| 15 |
# Step 1: Transcribe the uploaded audio file using Whisper
|
| 16 |
transcription_result = whisper_model.transcribe(audio_path)
|
|
|
|
| 19 |
# Step 2: Summarize the transcribed text using a pre-trained summarization model
|
| 20 |
summary = summarizer(transcription, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
|
| 21 |
|
| 22 |
+
# Step 3: Convert the summarized text into speech using the Hugging Face TTS model
|
| 23 |
+
# Breakdown into multiple steps
|
| 24 |
+
tts = gTTS(text=summary, lang='en') # Generate the TTS output
|
| 25 |
+
tts.save("summarized_audio.wav")
|
| 26 |
+
|
| 27 |
+
# Save the TTS audio to a file (WAV format)
|
| 28 |
|
| 29 |
+
|
| 30 |
+
# Return the path to the saved summarized audio file
|
| 31 |
+
return "summarized_audio.wav"
|
| 32 |
|
| 33 |
# Gradio interface
|
| 34 |
interface = gr.Interface(
|
| 35 |
fn=summarize_audio, # The function to process the audio and return summarized audio
|
| 36 |
inputs=gr.Audio(type="filepath", label="Upload your audio file"), # Accept audio file uploads, file path as input
|
| 37 |
+
outputs=gr.File(label="Download Summarized Audio"), # Provide a downloadable summarized audio file
|
|
|
|
| 38 |
title="Audio Summarizer", # Interface title
|
| 39 |
+
description="Upload an audio file, and this tool will summarize it and generate a downloadable audio summary." , # Interface description
|
| 40 |
examples=[["audio_sample1.mp3"]]
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
# Launch the Gradio interface
|
| 44 |
+
interface.launch(debug=True)
|