Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
from transformers import pipeline
|
4 |
from langdetect import detect
|
5 |
|
6 |
-
def process_audio(
|
7 |
try:
|
8 |
-
#
|
9 |
-
audio_path = audio_file if isinstance(audio_file, str) else audio_file.name
|
10 |
-
|
11 |
-
# Transcribe
|
12 |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-large")
|
13 |
result = asr(audio_path)
|
14 |
transcript = result["text"]
|
15 |
except Exception as e:
|
16 |
-
return "Error in transcription: "
|
17 |
try:
|
18 |
detected_lang = detect(transcript)
|
19 |
except Exception:
|
@@ -38,10 +34,20 @@ def process_audio(audio_file):
|
|
38 |
summary_text = summary[0]["summary_text"]
|
39 |
except Exception as e:
|
40 |
summary_text = f"Error summarizing: {e}"
|
41 |
-
# Optionally, remove uploaded file if it's saved on disk
|
42 |
return lang_text, transcript, transcript_en, summary_text
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
-
gr.Markdown("## Audio Transcript, Translation & Summary (
|
46 |
audio_input = gr.Audio(source="upload", type="filepath", label="Upload MP3/WAV Audio")
|
47 |
-
btn = gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
3 |
from langdetect import detect
|
4 |
|
5 |
+
def process_audio(audio_path):
|
6 |
try:
|
7 |
+
# Transcription
|
|
|
|
|
|
|
8 |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-large")
|
9 |
result = asr(audio_path)
|
10 |
transcript = result["text"]
|
11 |
except Exception as e:
|
12 |
+
return f"Error in transcription: {e}", "", "", ""
|
13 |
try:
|
14 |
detected_lang = detect(transcript)
|
15 |
except Exception:
|
|
|
34 |
summary_text = summary[0]["summary_text"]
|
35 |
except Exception as e:
|
36 |
summary_text = f"Error summarizing: {e}"
|
|
|
37 |
return lang_text, transcript, transcript_en, summary_text
|
38 |
|
39 |
with gr.Blocks() as demo:
|
40 |
+
gr.Markdown("## Audio Transcript, Translation & Summary (Whisper + Hugging Face)")
|
41 |
audio_input = gr.Audio(source="upload", type="filepath", label="Upload MP3/WAV Audio")
|
42 |
+
btn = gr.Button("Process")
|
43 |
+
lang_out = gr.Textbox(label="Detected Language")
|
44 |
+
transcript_out = gr.Textbox(label="Original Transcript")
|
45 |
+
transcript_en_out = gr.Textbox(label="English Transcript (if translated)")
|
46 |
+
summary_out = gr.Textbox(label="Summary")
|
47 |
+
btn.click(
|
48 |
+
process_audio,
|
49 |
+
inputs=[audio_input],
|
50 |
+
outputs=[lang_out, transcript_out, transcript_en_out, summary_out]
|
51 |
+
)
|
52 |
+
|
53 |
+
demo.launch()
|