Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
import subprocess
|
4 |
from transformers import pipeline
|
5 |
from langdetect import detect
|
6 |
|
7 |
-
def
|
8 |
-
output_file = "audio.mp3"
|
9 |
-
# Remove old file if exists
|
10 |
-
if os.path.exists(output_file):
|
11 |
-
os.remove(output_file)
|
12 |
-
cmd = [
|
13 |
-
"yt-dlp", "-x", "--audio-format", "mp3", "-o", output_file, youtube_url
|
14 |
-
]
|
15 |
-
subprocess.run(cmd, check=True)
|
16 |
-
return output_file
|
17 |
-
|
18 |
-
def process_youtube(youtube_url):
|
19 |
-
try:
|
20 |
-
audio_path = download_audio(youtube_url)
|
21 |
-
except Exception as e:
|
22 |
-
return "Error downloading audio: " + str(e), "", "", ""
|
23 |
try:
|
|
|
|
|
|
|
|
|
24 |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-large")
|
25 |
result = asr(audio_path)
|
26 |
transcript = result["text"]
|
@@ -50,22 +38,10 @@ def process_youtube(youtube_url):
|
|
50 |
summary_text = summary[0]["summary_text"]
|
51 |
except Exception as e:
|
52 |
summary_text = f"Error summarizing: {e}"
|
53 |
-
if
|
54 |
-
os.remove(audio_path)
|
55 |
return lang_text, transcript, transcript_en, summary_text
|
56 |
|
57 |
with gr.Blocks() as demo:
|
58 |
-
gr.Markdown("##
|
59 |
-
|
60 |
-
btn = gr
|
61 |
-
lang_out = gr.Textbox(label="Detected Language")
|
62 |
-
transcript_out = gr.Textbox(label="Original Transcript")
|
63 |
-
transcript_en_out = gr.Textbox(label="English Transcript (if translated)")
|
64 |
-
summary_out = gr.Textbox(label="Summary")
|
65 |
-
btn.click(
|
66 |
-
process_youtube,
|
67 |
-
inputs=[url_input],
|
68 |
-
outputs=[lang_out, transcript_out, transcript_en_out, summary_out]
|
69 |
-
)
|
70 |
-
|
71 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
from transformers import pipeline
|
4 |
from langdetect import detect
|
5 |
|
6 |
+
def process_audio(audio_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
try:
|
8 |
+
# audio_file is a tuple (file_obj, file_path)
|
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"]
|
|
|
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 (Powered by Whisper + Hugging Face)")
|
46 |
+
audio_input = gr.Audio(source="upload", type="filepath", label="Upload MP3/WAV Audio")
|
47 |
+
btn = gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|