Update app.py
Browse files
app.py
CHANGED
|
@@ -71,10 +71,11 @@ def download_audio_youtube(url, output_path="audio.wav", cookies_path=None):
|
|
| 71 |
raise RuntimeError(
|
| 72 |
"\u26a0\ufe0f Could not download this YouTube video due to restrictions. "
|
| 73 |
"Please use this alternative tool to extract the transcript manually:\n\n"
|
| 74 |
-
f"https://youtubetotranscript.com/transcript?v={video_id}¤t_language_code=en"
|
| 75 |
)
|
| 76 |
|
| 77 |
|
|
|
|
| 78 |
return extract_audio_from_video(fallback_video_path, audio_path=output_path)
|
| 79 |
|
| 80 |
def download_video_direct(url, output_path="video.mp4"):
|
|
@@ -176,13 +177,8 @@ def generate_questions_with_pipeline(text, num_questions=5):
|
|
| 176 |
|
| 177 |
# === MAIN FUNCTION ===
|
| 178 |
|
| 179 |
-
def process_input_gradio(url_input, file_input, text_input
|
| 180 |
try:
|
| 181 |
-
cookies_path = None
|
| 182 |
-
if cookies_file is not None:
|
| 183 |
-
cookies_path = "cookies.txt"
|
| 184 |
-
shutil.copyfile(cookies_file.name, cookies_path)
|
| 185 |
-
|
| 186 |
transcript = ""
|
| 187 |
|
| 188 |
if text_input:
|
|
@@ -199,11 +195,15 @@ def process_input_gradio(url_input, file_input, text_input, cookies_file):
|
|
| 199 |
transcript = try_download_transcript(video_id)
|
| 200 |
if not transcript:
|
| 201 |
try:
|
| 202 |
-
audio_path = download_audio_youtube(url_input
|
| 203 |
chunks, sr = split_audio(audio_path, chunk_length_sec=15)
|
| 204 |
transcript = transcribe_chunks_dataset(chunks, sr)
|
| 205 |
except Exception as e:
|
| 206 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
else:
|
| 208 |
video_file = download_video_direct(url_input)
|
| 209 |
audio_path = extract_audio_from_video(video_file)
|
|
@@ -225,16 +225,16 @@ iface = gr.Interface(
|
|
| 225 |
inputs=[
|
| 226 |
gr.Textbox(label="YouTube or Direct Video URL", placeholder="https://..."),
|
| 227 |
gr.File(label="Or Upload a Video File", file_types=[".mp4", ".mkv", ".webm"]),
|
| 228 |
-
gr.Textbox(label="Or Paste Transcript/Text Directly", lines=10, placeholder="Paste transcript or text here...")
|
| 229 |
-
gr.File(label="Optional cookies.txt for YouTube", file_types=[".txt"])
|
| 230 |
-
|
| 231 |
],
|
| 232 |
outputs=[
|
| 233 |
gr.Textbox(label="Summary", lines=10),
|
| 234 |
gr.Textbox(label="Generated Questions", lines=10),
|
| 235 |
],
|
| 236 |
title="Lecture Summary & Question Generator",
|
| 237 |
-
description="Provide a YouTube/Direct video URL, upload a video file, or paste text. If the video is restricted, upload
|
| 238 |
)
|
| 239 |
|
|
|
|
|
|
|
| 240 |
iface.launch()
|
|
|
|
| 71 |
raise RuntimeError(
|
| 72 |
"\u26a0\ufe0f Could not download this YouTube video due to restrictions. "
|
| 73 |
"Please use this alternative tool to extract the transcript manually:\n\n"
|
| 74 |
+
f"<https://youtubetotranscript.com/transcript?v={video_id}¤t_language_code=en>"
|
| 75 |
)
|
| 76 |
|
| 77 |
|
| 78 |
+
|
| 79 |
return extract_audio_from_video(fallback_video_path, audio_path=output_path)
|
| 80 |
|
| 81 |
def download_video_direct(url, output_path="video.mp4"):
|
|
|
|
| 177 |
|
| 178 |
# === MAIN FUNCTION ===
|
| 179 |
|
| 180 |
+
def process_input_gradio(url_input, file_input, text_input):
|
| 181 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
transcript = ""
|
| 183 |
|
| 184 |
if text_input:
|
|
|
|
| 195 |
transcript = try_download_transcript(video_id)
|
| 196 |
if not transcript:
|
| 197 |
try:
|
| 198 |
+
audio_path = download_audio_youtube(url_input)
|
| 199 |
chunks, sr = split_audio(audio_path, chunk_length_sec=15)
|
| 200 |
transcript = transcribe_chunks_dataset(chunks, sr)
|
| 201 |
except Exception as e:
|
| 202 |
+
return (
|
| 203 |
+
f"\u26a0\ufe0f Could not download this YouTube video due to restrictions. "
|
| 204 |
+
"Please upload the video manually.\n"
|
| 205 |
+
f"Details: {e}", ""
|
| 206 |
+
)
|
| 207 |
else:
|
| 208 |
video_file = download_video_direct(url_input)
|
| 209 |
audio_path = extract_audio_from_video(video_file)
|
|
|
|
| 225 |
inputs=[
|
| 226 |
gr.Textbox(label="YouTube or Direct Video URL", placeholder="https://..."),
|
| 227 |
gr.File(label="Or Upload a Video File", file_types=[".mp4", ".mkv", ".webm"]),
|
| 228 |
+
gr.Textbox(label="Or Paste Transcript/Text Directly", lines=10, placeholder="Paste transcript or text here...")
|
|
|
|
|
|
|
| 229 |
],
|
| 230 |
outputs=[
|
| 231 |
gr.Textbox(label="Summary", lines=10),
|
| 232 |
gr.Textbox(label="Generated Questions", lines=10),
|
| 233 |
],
|
| 234 |
title="Lecture Summary & Question Generator",
|
| 235 |
+
description="Provide a YouTube/Direct video URL, upload a video file, or paste text. If the video is restricted, upload the video file directly."
|
| 236 |
)
|
| 237 |
|
| 238 |
+
|
| 239 |
+
|
| 240 |
iface.launch()
|