Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,53 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
|
|
|
|
|
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
|
|
|
|
7 |
|
8 |
# Load Summarization model
|
9 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
|
11 |
-
# Function to transcribe and summarize audio
|
12 |
-
def transcribe_and_summarize(audio_file):
|
13 |
-
if audio_file is None:
|
14 |
-
return "Error: No audio file provided.", ""
|
15 |
|
|
|
16 |
try:
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
except Exception as e:
|
34 |
return f"Error: {str(e)}", ""
|
35 |
|
36 |
-
|
|
|
37 |
iface = gr.Interface(
|
38 |
-
fn=
|
39 |
-
inputs=gr.
|
40 |
-
outputs=[
|
41 |
-
|
42 |
-
|
43 |
-
]
|
44 |
)
|
45 |
|
46 |
-
|
47 |
-
port = int(os.environ.get('PORT1', 7860))
|
48 |
-
|
49 |
-
# Launch Gradio app
|
50 |
-
iface.launch(share=True, server_port=port)
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
import os
|
4 |
+
import subprocess
|
5 |
+
from pytubefix import YouTube
|
6 |
+
from moviepy.editor import VideoFileClip
|
7 |
from transformers import pipeline
|
8 |
|
9 |
+
# Ensure required packages are installed inside Hugging Face Spaces
|
10 |
+
subprocess.run(["pip", "install", "pytubefix", "moviepy", "transformers", "torchaudio"], check=True)
|
11 |
+
|
12 |
+
# Load Whisper model for transcription
|
13 |
+
asr = pipeline("automatic-speech-recognition", model="distil-whisper/distil-small.en")
|
14 |
|
15 |
# Load Summarization model
|
16 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
17 |
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
def process_youtube_link(youtube_url):
|
20 |
try:
|
21 |
+
# Download YouTube Video
|
22 |
+
yt = YouTube(youtube_url)
|
23 |
+
video_stream = yt.streams.filter(only_audio=True).first()
|
24 |
+
video_path = video_stream.download(filename="video.mp4")
|
25 |
+
|
26 |
+
# Extract Audio
|
27 |
+
audio_path = "audio.wav"
|
28 |
+
video = VideoFileClip(video_path)
|
29 |
+
video.audio.write_audiofile(audio_path)
|
30 |
+
|
31 |
+
# Transcribe Audio
|
32 |
+
transcription = asr(audio_path)
|
33 |
+
transcribed_text = transcription["text"]
|
34 |
+
|
35 |
+
# Summarize Transcription
|
36 |
+
summary = summarizer(transcribed_text, max_length=150, min_length=50, do_sample=False)[0]["summary_text"]
|
37 |
+
|
38 |
+
return transcribed_text, summary
|
39 |
|
40 |
except Exception as e:
|
41 |
return f"Error: {str(e)}", ""
|
42 |
|
43 |
+
|
44 |
+
# Create Gradio Interface
|
45 |
iface = gr.Interface(
|
46 |
+
fn=process_youtube_link,
|
47 |
+
inputs=gr.Textbox(label="Enter YouTube URL"),
|
48 |
+
outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
|
49 |
+
title="YouTube Video Transcriber & Summarizer",
|
50 |
+
description="Enter a YouTube link, and this app will transcribe and summarize the audio.",
|
|
|
51 |
)
|
52 |
|
53 |
+
iface.launch()
|
|
|
|
|
|
|
|