Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,19 +2,13 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
from langdetect import detect
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
SUMMARIZER_MODEL = "facebook/bart-large-cnn"
|
8 |
-
|
9 |
-
# Load pipelines ONCE at startup
|
10 |
-
asr = pipeline("automatic-speech-recognition", model=WHISPER_MODEL)
|
11 |
-
summarizer = pipeline("summarization", model=SUMMARIZER_MODEL)
|
12 |
|
13 |
def process_audio(audio_path):
|
14 |
-
if not audio_path or
|
15 |
return "No audio file provided.", "", "", ""
|
16 |
try:
|
17 |
-
# Transcription
|
18 |
result = asr(audio_path)
|
19 |
transcript = result["text"]
|
20 |
except Exception as e:
|
@@ -28,7 +22,6 @@ def process_audio(audio_path):
|
|
28 |
transcript_en = transcript
|
29 |
if detected_lang != "en":
|
30 |
try:
|
31 |
-
# Use the same pipeline, but set task as "translate" for Whisper
|
32 |
result_translate = asr(audio_path, generate_kwargs={"task": "translate"})
|
33 |
transcript_en = result_translate["text"]
|
34 |
except Exception as e:
|
@@ -40,18 +33,17 @@ def process_audio(audio_path):
|
|
40 |
summary_text = f"Error summarizing: {e}"
|
41 |
return lang_text, transcript, transcript_en, summary_text
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
)
|
56 |
|
57 |
-
|
|
|
2 |
from transformers import pipeline
|
3 |
from langdetect import detect
|
4 |
|
5 |
+
asr = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
6 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def process_audio(audio_path):
|
9 |
+
if not audio_path or isinstance(audio_path, bool):
|
10 |
return "No audio file provided.", "", "", ""
|
11 |
try:
|
|
|
12 |
result = asr(audio_path)
|
13 |
transcript = result["text"]
|
14 |
except Exception as e:
|
|
|
22 |
transcript_en = transcript
|
23 |
if detected_lang != "en":
|
24 |
try:
|
|
|
25 |
result_translate = asr(audio_path, generate_kwargs={"task": "translate"})
|
26 |
transcript_en = result_translate["text"]
|
27 |
except Exception as e:
|
|
|
33 |
summary_text = f"Error summarizing: {e}"
|
34 |
return lang_text, transcript, transcript_en, summary_text
|
35 |
|
36 |
+
iface = gr.Interface(
|
37 |
+
fn=process_audio,
|
38 |
+
inputs=gr.Audio(source="upload", type="filepath", label="Upload MP3/WAV Audio"),
|
39 |
+
outputs=[
|
40 |
+
gr.Textbox(label="Detected Language"),
|
41 |
+
gr.Textbox(label="Original Transcript"),
|
42 |
+
gr.Textbox(label="English Transcript (if translated)"),
|
43 |
+
gr.Textbox(label="Summary"),
|
44 |
+
],
|
45 |
+
title="Audio Transcript, Translation & Summary",
|
46 |
+
description="Upload your audio file (MP3/WAV). This app transcribes, detects language, translates to English if needed, and summarizes."
|
47 |
+
)
|
|
|
48 |
|
49 |
+
iface.launch()
|