ani-quiz / app.py
JUNGU's picture
Update app.py
1a84c5a verified
from youtube_worksheet import YouTubeWorksheet
from dotenv import load_dotenv
import gradio as gr
import os
def process_video(url):
# ν™˜κ²½λ³€μˆ˜μ—μ„œ API ν‚€ κ°€μ Έμ˜€κΈ°
API_KEY = os.getenv('GEMINI_API_KEY')
if not API_KEY:
return "ERROR: GEMINI_API_KEYκ°€ μ„€μ •λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. .env νŒŒμΌμ„ ν™•μΈν•΄μ£Όμ„Έμš”."
worksheet = YouTubeWorksheet(API_KEY)
# μžλ§‰ μΆ”μΆœ
transcript = worksheet.get_transcript(url)
if not transcript:
return "μžλ§‰μ„ μΆ”μΆœν•  수 μ—†μŠ΅λ‹ˆλ‹€."
# μ›Œν¬μ‹œνŠΈ 생성
content = worksheet.create_worksheet(transcript)
# DOCX 파일둜 μ €μž₯
output_file = worksheet.save_to_docx(content)
return f"μ›Œν¬μ‹œνŠΈκ°€ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 파일λͺ…: {output_file}", output_file
def main():
# Gradio μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
iface = gr.Interface(
fn=process_video,
inputs=[gr.Textbox(label="YouTube URL을 μž…λ ₯ν•˜μ„Έμš”")],
outputs=[gr.Textbox(label="처리 κ²°κ³Ό"), gr.File(label="μƒμ„±λœ μ›Œν¬μ‹œνŠΈ")],
title="YouTube ν•™μŠ΅ μ›Œν¬μ‹œνŠΈ 생성기",
description="YouTube μ˜μƒμ˜ μžλ§‰μ„ μ΄μš©ν•˜μ—¬ ν•™μŠ΅ μ›Œν¬μ‹œνŠΈλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€."
)
iface.launch(share=True)
if __name__ == '__main__':
load_dotenv()
main()