Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 4 |
+
|
| 5 |
+
def extract_script(url):
|
| 6 |
+
# '=' 기호 이후 텍스트 추출
|
| 7 |
+
try:
|
| 8 |
+
video_id = url.split('=')[-1]
|
| 9 |
+
|
| 10 |
+
# 자막(스크립트) 가져오기
|
| 11 |
+
srt = YouTubeTranscriptApi.get_transcript(video_id, languages=['ko'])
|
| 12 |
+
|
| 13 |
+
# 자막 텍스트 합치기
|
| 14 |
+
script = "\n".join([i["text"] for i in srt])
|
| 15 |
+
return script
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return f"오류 발생: {e}"
|
| 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 |
+
extract_button.click(extract_script, inputs=url_input, outputs=output)
|
| 27 |
+
|
| 28 |
+
# 웹 앱 실행
|
| 29 |
+
app.launch()
|