|
import gradio as gr |
|
import random |
|
|
|
|
|
def extract_subtitles(video_url): |
|
|
|
|
|
subtitles = [ |
|
"影片介紹了機器學習的基本概念。", |
|
"機器學習主要分為監督學習和非監督學習。", |
|
"決策樹是一種常用的機器學習算法。", |
|
"神經網絡是深度學習的基礎。", |
|
"支持向量機適用於分類問題。", |
|
"在訓練過程中,我們需要使用大量的數據。", |
|
"模型過擬合是機器學習中的一個常見問題。", |
|
"正則化技術可以幫助防止過擬合。", |
|
"卷積神經網絡在圖像處理中有廣泛應用。", |
|
"強化學習是一種基於獎勵的學習方法。" |
|
] |
|
return subtitles |
|
|
|
|
|
def generate_questions(video_url): |
|
subtitles = extract_subtitles(video_url) |
|
questions = [] |
|
for i in range(10): |
|
sentence = random.choice(subtitles) |
|
question = f"根據影片中的以下句子生成問題: '{sentence}'" |
|
questions.append(question) |
|
return questions |
|
|
|
|
|
def interface(): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("## 影片習題產生器") |
|
|
|
|
|
video_url = gr.Textbox(label="影片連結") |
|
|
|
|
|
generate_btn = gr.Button("生成題目") |
|
|
|
|
|
questions_output = gr.Textbox(label="生成的題目", lines=10) |
|
|
|
|
|
generate_btn.click(fn=generate_questions, inputs=video_url, outputs=questions_output) |
|
|
|
return demo |
|
|
|
|
|
demo = interface() |
|
demo.launch() |
|
|
|
|
|
|