Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import whisper
|
3 |
+
from transformers import pipeline
|
4 |
+
import torch
|
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)
|
20 |
+
transcription = transcription_result["text"]
|
21 |
+
|
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 |
+
return summary
|
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 |
+
#outputs="text", # Provide a downloadable summarized audio file
|
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.", # Interface description
|
36 |
+
examples=[["audio_sample1.mp3"]]
|
37 |
+
|
38 |
+
|
39 |
+
)
|
40 |
+
|
41 |
+
# Launch the Gradio interface
|
42 |
+
interface.launch()
|