Spaces:
Sleeping
Sleeping
def get_meta_data(video_id, source="gcs"):
Browse files
app.py
CHANGED
@@ -573,6 +573,9 @@ def process_youtube_link(password, link):
|
|
573 |
mind_map_html = get_mind_map_html(mind_map)
|
574 |
reading_passage_json = get_reading_passage(video_id, formatted_simple_transcript, source)
|
575 |
reading_passage = reading_passage_json["reading_passage"]
|
|
|
|
|
|
|
576 |
|
577 |
# 确保返回与 UI 组件预期匹配的输出
|
578 |
return video_id, \
|
@@ -587,7 +590,9 @@ def process_youtube_link(password, link):
|
|
587 |
simple_html_content, \
|
588 |
first_image, \
|
589 |
first_text, \
|
590 |
-
reading_passage
|
|
|
|
|
591 |
|
592 |
def format_transcript_to_html(formatted_transcript):
|
593 |
html_content = ""
|
@@ -1005,6 +1010,48 @@ def change_questions(password, df_string):
|
|
1005 |
|
1006 |
|
1007 |
# AI 生成教學素材
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1008 |
def get_ai_content(password, video_id, df_string, topic, grade, level, specific_feature, content_type, source="gcs"):
|
1009 |
verify_password(password)
|
1010 |
if source == "gcs":
|
@@ -1712,7 +1759,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
1712 |
|
1713 |
with gr.Tab("教師版"):
|
1714 |
with gr.Row():
|
1715 |
-
|
1716 |
content_grade = gr.Dropdown(label="選擇年級", choices=["一年級", "二年級", "三年級", "四年級", "五年級", "六年級", "七年級", "八年級", "九年級", "十年級", "十一年級", "十二年級"], value="三年級")
|
1717 |
content_level = gr.Dropdown(label="差異化教學", choices=["基礎", "中級", "進階"], value="基礎")
|
1718 |
with gr.Row():
|
@@ -1844,44 +1891,33 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
1844 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
1845 |
|
1846 |
# 当输入 YouTube 链接时触发
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1847 |
youtube_link.change(
|
1848 |
process_youtube_link,
|
1849 |
inputs=[password,youtube_link],
|
1850 |
-
outputs=
|
1851 |
-
video_id,
|
1852 |
-
btn_1,
|
1853 |
-
btn_2,
|
1854 |
-
btn_3,
|
1855 |
-
df_string_output,
|
1856 |
-
df_summarise,
|
1857 |
-
mind_map,
|
1858 |
-
mind_map_html,
|
1859 |
-
transcript_html,
|
1860 |
-
simple_html_content,
|
1861 |
-
slide_image,
|
1862 |
-
slide_text,
|
1863 |
-
reading_passage
|
1864 |
-
]
|
1865 |
)
|
1866 |
|
1867 |
youtube_link_btn.click(
|
1868 |
process_youtube_link,
|
1869 |
inputs=[password, youtube_link],
|
1870 |
-
outputs=
|
1871 |
-
video_id,
|
1872 |
-
btn_1,
|
1873 |
-
btn_2,
|
1874 |
-
btn_3,
|
1875 |
-
df_string_output,
|
1876 |
-
df_summarise,
|
1877 |
-
mind_map,
|
1878 |
-
mind_map_html,
|
1879 |
-
transcript_html,
|
1880 |
-
simple_html_content,
|
1881 |
-
slide_image,
|
1882 |
-
slide_text,
|
1883 |
-
reading_passage
|
1884 |
-
]
|
1885 |
)
|
1886 |
|
1887 |
# 当输入网页链接时触发
|
@@ -1897,17 +1933,17 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
1897 |
# 教師版 學習單
|
1898 |
worksheet_content_btn.click(
|
1899 |
get_ai_content,
|
1900 |
-
inputs=[password, video_id, df_string_output,
|
1901 |
outputs=[worksheet_exam_result_original, worksheet_exam_result, worksheet_prompt, worksheet_exam_result_prompt]
|
1902 |
)
|
1903 |
lesson_plan_btn.click(
|
1904 |
get_ai_content,
|
1905 |
-
inputs=[password, video_id, df_string_output,
|
1906 |
outputs=[lesson_plan_exam_result_original, lesson_plan_exam_result, lesson_plan_prompt, lesson_plan_exam_result_prompt]
|
1907 |
)
|
1908 |
exit_ticket_btn.click(
|
1909 |
get_ai_content,
|
1910 |
-
inputs=[password, video_id, df_string_output,
|
1911 |
outputs=[exit_ticket_exam_result_original, exit_ticket_exam_result, exit_ticket_prompt, exit_ticket_exam_result_prompt]
|
1912 |
)
|
1913 |
|
|
|
573 |
mind_map_html = get_mind_map_html(mind_map)
|
574 |
reading_passage_json = get_reading_passage(video_id, formatted_simple_transcript, source)
|
575 |
reading_passage = reading_passage_json["reading_passage"]
|
576 |
+
meta_data = get_meta_data(video_id)
|
577 |
+
subject = meta_data["subject"]
|
578 |
+
grade = meta_data["grade"]
|
579 |
|
580 |
# 确保返回与 UI 组件预期匹配的输出
|
581 |
return video_id, \
|
|
|
590 |
simple_html_content, \
|
591 |
first_image, \
|
592 |
first_text, \
|
593 |
+
reading_passage, \
|
594 |
+
subject, \
|
595 |
+
grade
|
596 |
|
597 |
def format_transcript_to_html(formatted_transcript):
|
598 |
html_content = ""
|
|
|
1010 |
|
1011 |
|
1012 |
# AI 生成教學素材
|
1013 |
+
def get_meta_data(video_id, source="gcs"):
|
1014 |
+
if source == "gcs":
|
1015 |
+
print("===get_meta_data on gcs===")
|
1016 |
+
gcs_client = GCS_CLIENT
|
1017 |
+
bucket_name = 'video_ai_assistant'
|
1018 |
+
file_name = f'{video_id}_meta_data.json'
|
1019 |
+
blob_name = f"{video_id}/{file_name}"
|
1020 |
+
# 检查檔案是否存在
|
1021 |
+
is_file_exists = GCS_SERVICE.check_file_exists(bucket_name, blob_name)
|
1022 |
+
if not is_file_exists:
|
1023 |
+
meta_data_json = {
|
1024 |
+
"subject": "",
|
1025 |
+
"grade": "",
|
1026 |
+
}
|
1027 |
+
print("meta_data empty return")
|
1028 |
+
else:
|
1029 |
+
# meta_data已存在,下载内容
|
1030 |
+
print("meta_data已存在于GCS中")
|
1031 |
+
meta_data_text = download_blob_to_string(gcs_client, bucket_name, blob_name)
|
1032 |
+
meta_data_json = json.loads(meta_data_text)
|
1033 |
+
|
1034 |
+
# meta_data_json grade 數字轉換成文字
|
1035 |
+
grade = meta_data_json["grade"]
|
1036 |
+
case = {
|
1037 |
+
1: "一年級",
|
1038 |
+
2: "二年級",
|
1039 |
+
3: "三年級",
|
1040 |
+
4: "四年級",
|
1041 |
+
5: "五年級",
|
1042 |
+
6: "六年級",
|
1043 |
+
7: "七年級",
|
1044 |
+
8: "八年級",
|
1045 |
+
9: "九年級",
|
1046 |
+
10: "十年級",
|
1047 |
+
11: "十一年級",
|
1048 |
+
12: "十二年級",
|
1049 |
+
}
|
1050 |
+
grade_text = case.get(grade, "")
|
1051 |
+
meta_data_json["grade"] = grade_text
|
1052 |
+
|
1053 |
+
return meta_data_json
|
1054 |
+
|
1055 |
def get_ai_content(password, video_id, df_string, topic, grade, level, specific_feature, content_type, source="gcs"):
|
1056 |
verify_password(password)
|
1057 |
if source == "gcs":
|
|
|
1759 |
|
1760 |
with gr.Tab("教師版"):
|
1761 |
with gr.Row():
|
1762 |
+
content_subject = gr.Dropdown(label="選擇主題", choices=["數學", "自然", "國文", "英文", "社會","物理", "化學", "生物", "地理", "歷史", "公民"], value="數學")
|
1763 |
content_grade = gr.Dropdown(label="選擇年級", choices=["一年級", "二年級", "三年級", "四年級", "五年級", "六年級", "七年級", "八年級", "九年級", "十年級", "十一年級", "十二年級"], value="三年級")
|
1764 |
content_level = gr.Dropdown(label="差異化教學", choices=["基礎", "中級", "進階"], value="基礎")
|
1765 |
with gr.Row():
|
|
|
1891 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
1892 |
|
1893 |
# 当输入 YouTube 链接时触发
|
1894 |
+
process_youtube_link_output = [
|
1895 |
+
video_id,
|
1896 |
+
btn_1,
|
1897 |
+
btn_2,
|
1898 |
+
btn_3,
|
1899 |
+
df_string_output,
|
1900 |
+
df_summarise,
|
1901 |
+
mind_map,
|
1902 |
+
mind_map_html,
|
1903 |
+
transcript_html,
|
1904 |
+
simple_html_content,
|
1905 |
+
slide_image,
|
1906 |
+
slide_text,
|
1907 |
+
reading_passage,
|
1908 |
+
content_subject,
|
1909 |
+
content_grade,
|
1910 |
+
]
|
1911 |
youtube_link.change(
|
1912 |
process_youtube_link,
|
1913 |
inputs=[password,youtube_link],
|
1914 |
+
outputs=process_youtube_link_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1915 |
)
|
1916 |
|
1917 |
youtube_link_btn.click(
|
1918 |
process_youtube_link,
|
1919 |
inputs=[password, youtube_link],
|
1920 |
+
outputs=process_youtube_link_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1921 |
)
|
1922 |
|
1923 |
# 当输入网页链接时触发
|
|
|
1933 |
# 教師版 學習單
|
1934 |
worksheet_content_btn.click(
|
1935 |
get_ai_content,
|
1936 |
+
inputs=[password, video_id, df_string_output, content_subject, content_grade, content_level, worksheet_algorithm, worksheet_content_type_name],
|
1937 |
outputs=[worksheet_exam_result_original, worksheet_exam_result, worksheet_prompt, worksheet_exam_result_prompt]
|
1938 |
)
|
1939 |
lesson_plan_btn.click(
|
1940 |
get_ai_content,
|
1941 |
+
inputs=[password, video_id, df_string_output, content_subject, content_grade, content_level, lesson_plan_time, lesson_plan_content_type_name],
|
1942 |
outputs=[lesson_plan_exam_result_original, lesson_plan_exam_result, lesson_plan_prompt, lesson_plan_exam_result_prompt]
|
1943 |
)
|
1944 |
exit_ticket_btn.click(
|
1945 |
get_ai_content,
|
1946 |
+
inputs=[password, video_id, df_string_output, content_subject, content_grade, content_level, exit_ticket_time, exit_ticket_content_type_name],
|
1947 |
outputs=[exit_ticket_exam_result_original, exit_ticket_exam_result, exit_ticket_prompt, exit_ticket_exam_result_prompt]
|
1948 |
)
|
1949 |
|