Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load Whisper pipeline (speech-to-text)
|
| 5 |
+
asr_pipe = pipeline(
|
| 6 |
+
task="automatic-speech-recognition",
|
| 7 |
+
model="openai/whisper-small",
|
| 8 |
+
return_timestamps=True
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Load summarization pipeline
|
| 12 |
+
summarizer = pipeline("summarization", model="google/pegasus-cnn_dailymail")
|
| 13 |
+
|
| 14 |
+
# Function to transcribe and summarize
|
| 15 |
+
def transcribe_and_summarize(audio_file):
|
| 16 |
+
if audio_file is None:
|
| 17 |
+
return "Please upload an audio file.", ""
|
| 18 |
+
|
| 19 |
+
# Transcription
|
| 20 |
+
transcript = asr_pipe(audio_file)["text"]
|
| 21 |
+
|
| 22 |
+
# Summarization (limit to 1024 tokens for safety)
|
| 23 |
+
if len(transcript) > 1000:
|
| 24 |
+
transcript = transcript[:1000] # truncate long transcripts
|
| 25 |
+
summary = summarizer(transcript, max_length=80, min_length=20, do_sample=False)[0]["summary_text"]
|
| 26 |
+
|
| 27 |
+
return transcript, summary
|
| 28 |
+
|
| 29 |
+
# Gradio Interface
|
| 30 |
+
with gr.Blocks() as app:
|
| 31 |
+
gr.Markdown("## 🎙️ Whisper ASR + Summary\nUpload or record audio to get a transcription and summary.")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
audio_input = gr.Audio(type="filepath", label="Upload or Record Audio")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
transcribe_btn = gr.Button("Transcribe & Summarize")
|
| 38 |
+
|
| 39 |
+
with gr.Row():
|
| 40 |
+
transcript_box = gr.Textbox(label="Transcription", lines=6)
|
| 41 |
+
summary_box = gr.Textbox(label="Summary", lines=4)
|
| 42 |
+
|
| 43 |
+
transcribe_btn.click(fn=transcribe_and_summarize, inputs=audio_input, outputs=[transcript_box, summary_box])
|
| 44 |
+
|
| 45 |
+
app.launch() #summarize is added but taking lon time and also sumary is not accurate
|