Add Gradio app for audio transcription and summarization
Browse files
app.py
CHANGED
|
@@ -1,33 +1,35 @@
|
|
| 1 |
-
import whisper
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Load models
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
result = model.transcribe(file_path)
|
| 9 |
-
return result["text"]
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
description="Upload an audio file to get a transcription and extract main topics."
|
| 30 |
)
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import whisper
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Load models
|
| 6 |
+
model = whisper.load_model("base")
|
| 7 |
+
summarizer = pipeline("summarization", model="t5-small")
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Function to transcribe and summarize
|
| 10 |
+
def transcribe_and_summarize(audio_file):
|
| 11 |
+
# Transcription
|
| 12 |
+
result = model.transcribe(audio_file)
|
| 13 |
+
transcription = result["text"]
|
| 14 |
+
|
| 15 |
+
# Summarization
|
| 16 |
+
summary = summarizer(transcription, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
|
| 17 |
+
return transcription, summary
|
| 18 |
|
| 19 |
+
# Gradio Interface
|
| 20 |
+
inputs = gr.Audio(type="filepath", label="Upload your audio file")
|
| 21 |
+
outputs = [
|
| 22 |
+
gr.Textbox(label="Transcription"),
|
| 23 |
+
gr.Textbox(label="Summary")
|
| 24 |
+
]
|
| 25 |
|
| 26 |
+
app = gr.Interface(
|
| 27 |
+
fn=transcribe_and_summarize,
|
| 28 |
+
inputs=inputs,
|
| 29 |
+
outputs=outputs,
|
| 30 |
+
title="Audio Transcription and Summarization",
|
| 31 |
+
description="Upload an audio file to get its transcription and a summarized version of the content."
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
+
# Launch the app
|
| 35 |
+
app.launch()
|