Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,48 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
from youtube_transcript_api import YouTubeTranscriptApi
|
|
|
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
-
return f"
|
| 18 |
-
|
| 19 |
-
# Gradio ์ธํฐํ์ด์ค ์ ์
|
| 20 |
-
with gr.Blocks() as app:
|
| 21 |
-
gr.Markdown("## ์ ํ๋ธ ์คํฌ๋ฆฝํธ ์ถ์ถ๊ธฐ")
|
| 22 |
-
url_input = gr.Textbox(label="์ ํ๋ธ URL", placeholder="์์ https://www.youtube.com/watch?v=HtMVLneHZR0")
|
| 23 |
-
output = gr.Textbox(label="์คํฌ๋ฆฝํธ ์ถ๋ ฅ")
|
| 24 |
-
extract_button = gr.Button("์คํฌ๋ฆฝํธ ์ถ์ถ")
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
+
def extract_video_id(url):
|
| 6 |
+
"""YouTube URL์์ ๋น๋์ค ID๋ฅผ ์ถ์ถํ๋ ํจ์"""
|
| 7 |
+
video_id = None
|
| 8 |
+
if 'youtube.com/watch?v=' in url:
|
| 9 |
+
video_id = url.split('youtube.com/watch?v=')[1][:11]
|
| 10 |
+
elif 'youtu.be/' in url:
|
| 11 |
+
video_id = url.split('youtu.be/')[1][:11]
|
| 12 |
+
return video_id
|
| 13 |
|
| 14 |
+
def get_transcript(url):
|
| 15 |
+
"""YouTube ์์์ ์คํฌ๋ฆฝํธ๋ฅผ ์ถ์ถํ๋ ํจ์"""
|
| 16 |
+
try:
|
| 17 |
+
video_id = extract_video_id(url)
|
| 18 |
+
if not video_id:
|
| 19 |
+
return "์ฌ๋ฐ๋ฅธ YouTube URL์ ์
๋ ฅํด์ฃผ์ธ์."
|
| 20 |
+
|
| 21 |
+
transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=['ko', 'en'])
|
| 22 |
+
|
| 23 |
+
# ์ ์ฒด ์คํฌ๋ฆฝํธ ํ
์คํธ ๊ตฌ์ฑ
|
| 24 |
+
full_transcript = ""
|
| 25 |
+
for transcript in transcript_list:
|
| 26 |
+
text = transcript['text']
|
| 27 |
+
timestamp = transcript['start']
|
| 28 |
+
minutes = int(timestamp // 60)
|
| 29 |
+
seconds = int(timestamp % 60)
|
| 30 |
+
full_transcript += f"[{minutes:02d}:{seconds:02d}] {text}\n"
|
| 31 |
+
|
| 32 |
+
return full_transcript
|
| 33 |
+
|
| 34 |
except Exception as e:
|
| 35 |
+
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=get_transcript,
|
| 40 |
+
inputs=gr.Textbox(label="YouTube URL์ ์
๋ ฅํ์ธ์"),
|
| 41 |
+
outputs=gr.Textbox(label="์ถ์ถ๋ ์คํฌ๋ฆฝํธ", lines=10),
|
| 42 |
+
title="YouTube ์คํฌ๋ฆฝํธ ์ถ์ถ๊ธฐ",
|
| 43 |
+
description="YouTube ์์์ URL์ ์
๋ ฅํ๋ฉด ์๋์ผ๋ก ์คํฌ๋ฆฝํธ๋ฅผ ์ถ์ถํฉ๋๋ค."
|
| 44 |
+
)
|
| 45 |
|
| 46 |
+
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
iface.launch()
|