Spaces:
Sleeping
Sleeping
elif kind == "key_moments":
Browse files
app.py
CHANGED
@@ -610,7 +610,6 @@ def process_youtube_link(password, link):
|
|
610 |
# 基于逐字稿生成其他所需的输出
|
611 |
source = "gcs"
|
612 |
questions = get_questions(video_id, formatted_simple_transcript, source)
|
613 |
-
formatted_transcript_json = json.dumps(formatted_transcript, ensure_ascii=False, indent=2)
|
614 |
summary_json = get_video_id_summary(video_id, formatted_simple_transcript, source)
|
615 |
summary = summary_json["summary"]
|
616 |
key_moments_json = get_key_moments(video_id, formatted_simple_transcript, formatted_transcript, source)
|
@@ -650,6 +649,37 @@ def process_youtube_link(password, link):
|
|
650 |
subject, \
|
651 |
grade
|
652 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
def format_transcript_to_html(formatted_transcript):
|
654 |
html_content = ""
|
655 |
for entry in formatted_transcript:
|
@@ -1407,6 +1437,17 @@ def update_LLM_content(video_id, new_content, kind):
|
|
1407 |
mind_map_text = json.dumps(mind_map_json, ensure_ascii=False, indent=2)
|
1408 |
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, mind_map_text)
|
1409 |
updated_content = mind_map_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1410 |
elif kind == "transcript":
|
1411 |
if isinstance(new_content, str):
|
1412 |
transcript_json = json.loads(new_content)
|
@@ -1432,6 +1473,16 @@ def create_LLM_content(video_id, df_string, kind):
|
|
1432 |
elif kind == "mind_map":
|
1433 |
content = generate_mind_map(df_string)
|
1434 |
update_LLM_content(video_id, content, kind)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1435 |
elif kind == "transcript":
|
1436 |
content = process_transcript_and_screenshots_on_gcs(video_id)
|
1437 |
update_LLM_content(video_id, content, kind)
|
@@ -2086,8 +2137,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2086 |
ai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
2087 |
with gr.Row():
|
2088 |
ai_msg = gr.Textbox(label="Message",scale=3)
|
2089 |
-
ai_send_button = gr.Button("Send", variant="primary",scale=1)
|
2090 |
-
|
2091 |
with gr.Tab("文章模式"):
|
2092 |
with gr.Row() as reading_passage_admin:
|
2093 |
reading_passage_kind = gr.Textbox(value="reading_passage", show_label=False)
|
@@ -2111,7 +2161,6 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2111 |
with gr.Tab("關鍵時刻"):
|
2112 |
with gr.Row():
|
2113 |
key_moments_html = gr.HTML(value="")
|
2114 |
-
|
2115 |
with gr.Tab("教學備課"):
|
2116 |
with gr.Row():
|
2117 |
content_subject = gr.Dropdown(label="選擇主題", choices=["數學", "自然", "國文", "英文", "社會","物理", "化學", "生物", "地理", "歷史", "公民"], value="", visible=False)
|
@@ -2429,6 +2478,28 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2429 |
inputs=[video_id, df_string_output, transcript_kind],
|
2430 |
outputs=[df_string_output]
|
2431 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2432 |
|
2433 |
# 教師版
|
2434 |
worksheet_content_btn.click(
|
|
|
610 |
# 基于逐字稿生成其他所需的输出
|
611 |
source = "gcs"
|
612 |
questions = get_questions(video_id, formatted_simple_transcript, source)
|
|
|
613 |
summary_json = get_video_id_summary(video_id, formatted_simple_transcript, source)
|
614 |
summary = summary_json["summary"]
|
615 |
key_moments_json = get_key_moments(video_id, formatted_simple_transcript, formatted_transcript, source)
|
|
|
649 |
subject, \
|
650 |
grade
|
651 |
|
652 |
+
def create_formatted_simple_transcript(transcript):
|
653 |
+
formatted_simple_transcript = []
|
654 |
+
for entry in transcript:
|
655 |
+
start_time = format_seconds_to_time(entry['start'])
|
656 |
+
end_time = format_seconds_to_time(entry['start'] + entry['duration'])
|
657 |
+
line = {
|
658 |
+
"start_time": start_time,
|
659 |
+
"end_time": end_time,
|
660 |
+
"text": entry['text']
|
661 |
+
}
|
662 |
+
formatted_simple_transcript.append(line)
|
663 |
+
return formatted_simple_transcript
|
664 |
+
|
665 |
+
def create_formatted_transcript(transcript):
|
666 |
+
formatted_transcript = []
|
667 |
+
for entry in transcript:
|
668 |
+
start_time = format_seconds_to_time(entry['start'])
|
669 |
+
end_time = format_seconds_to_time(entry['start'] + entry['duration'])
|
670 |
+
embed_url = get_embedded_youtube_link(VIDEO_ID, entry['start'])
|
671 |
+
img_file_id = entry['img_file_id']
|
672 |
+
screenshot_path = img_file_id
|
673 |
+
line = {
|
674 |
+
"start_time": start_time,
|
675 |
+
"end_time": end_time,
|
676 |
+
"text": entry['text'],
|
677 |
+
"embed_url": embed_url,
|
678 |
+
"screenshot_path": screenshot_path
|
679 |
+
}
|
680 |
+
formatted_transcript.append(line)
|
681 |
+
return formatted_transcript
|
682 |
+
|
683 |
def format_transcript_to_html(formatted_transcript):
|
684 |
html_content = ""
|
685 |
for entry in formatted_transcript:
|
|
|
1437 |
mind_map_text = json.dumps(mind_map_json, ensure_ascii=False, indent=2)
|
1438 |
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, mind_map_text)
|
1439 |
updated_content = mind_map_text
|
1440 |
+
elif kind == "key_moments":
|
1441 |
+
# from update_LLM_btn -> new_content is a string
|
1442 |
+
# create_LLM_content -> new_content is a list
|
1443 |
+
if isinstance(new_content, str):
|
1444 |
+
key_moments_list = json.loads(new_content)
|
1445 |
+
else:
|
1446 |
+
key_moments_list = new_content
|
1447 |
+
key_moments_json = {"key_moments": key_moments_list}
|
1448 |
+
key_moments_text = json.dumps(key_moments_json, ensure_ascii=False, indent=2)
|
1449 |
+
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, key_moments_text)
|
1450 |
+
updated_content = key_moments_text
|
1451 |
elif kind == "transcript":
|
1452 |
if isinstance(new_content, str):
|
1453 |
transcript_json = json.loads(new_content)
|
|
|
1473 |
elif kind == "mind_map":
|
1474 |
content = generate_mind_map(df_string)
|
1475 |
update_LLM_content(video_id, content, kind)
|
1476 |
+
elif kind == "key_moments":
|
1477 |
+
if isinstance(df_string, str):
|
1478 |
+
transcript = json.loads(df_string)
|
1479 |
+
else:
|
1480 |
+
transcript = df_string
|
1481 |
+
formatted_simple_transcript = create_formatted_simple_transcript(transcript)
|
1482 |
+
formatted_transcript = create_formatted_transcript(transcript)
|
1483 |
+
content = generate_key_moments(formatted_simple_transcript, formatted_transcript)
|
1484 |
+
update_LLM_content(video_id, content, kind)
|
1485 |
+
content = json.dumps(content, ensure_ascii=False, indent=2)
|
1486 |
elif kind == "transcript":
|
1487 |
content = process_transcript_and_screenshots_on_gcs(video_id)
|
1488 |
update_LLM_content(video_id, content, kind)
|
|
|
2137 |
ai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
2138 |
with gr.Row():
|
2139 |
ai_msg = gr.Textbox(label="Message",scale=3)
|
2140 |
+
ai_send_button = gr.Button("Send", variant="primary",scale=1)
|
|
|
2141 |
with gr.Tab("文章模式"):
|
2142 |
with gr.Row() as reading_passage_admin:
|
2143 |
reading_passage_kind = gr.Textbox(value="reading_passage", show_label=False)
|
|
|
2161 |
with gr.Tab("關鍵時刻"):
|
2162 |
with gr.Row():
|
2163 |
key_moments_html = gr.HTML(value="")
|
|
|
2164 |
with gr.Tab("教學備課"):
|
2165 |
with gr.Row():
|
2166 |
content_subject = gr.Dropdown(label="選擇主題", choices=["數學", "自然", "國文", "英文", "社會","物理", "化學", "生物", "地理", "歷史", "公民"], value="", visible=False)
|
|
|
2478 |
inputs=[video_id, df_string_output, transcript_kind],
|
2479 |
outputs=[df_string_output]
|
2480 |
)
|
2481 |
+
|
2482 |
+
# key_moments event
|
2483 |
+
key_moments_create_button.click(
|
2484 |
+
create_LLM_content,
|
2485 |
+
inputs=[video_id, df_string_output, key_moments_kind],
|
2486 |
+
outputs=[key_moments]
|
2487 |
+
)
|
2488 |
+
key_moments_delete_button.click(
|
2489 |
+
delete_LLM_content,
|
2490 |
+
inputs=[video_id, key_moments_kind],
|
2491 |
+
outputs=[key_moments]
|
2492 |
+
)
|
2493 |
+
key_moments_edit_button.click(
|
2494 |
+
enable_edit_mode,
|
2495 |
+
inputs=[],
|
2496 |
+
outputs=[key_moments]
|
2497 |
+
)
|
2498 |
+
key_moments_update_button.click(
|
2499 |
+
update_LLM_content,
|
2500 |
+
inputs=[video_id, key_moments, key_moments_kind],
|
2501 |
+
outputs=[key_moments]
|
2502 |
+
)
|
2503 |
|
2504 |
# 教師版
|
2505 |
worksheet_content_btn.click(
|