Spaces:
Running
Running
questions admin
Browse files
app.py
CHANGED
@@ -610,6 +610,7 @@ def process_youtube_link(password, link):
|
|
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)
|
@@ -632,6 +633,7 @@ def process_youtube_link(password, link):
|
|
632 |
|
633 |
# 确保返回与 UI 组件预期匹配的输出
|
634 |
return video_id, \
|
|
|
635 |
questions[0] if len(questions) > 0 else "", \
|
636 |
questions[1] if len(questions) > 1 else "", \
|
637 |
questions[2] if len(questions) > 2 else "", \
|
@@ -1456,6 +1458,16 @@ def update_LLM_content(video_id, new_content, kind):
|
|
1456 |
transcript_text = json.dumps(transcript_json, ensure_ascii=False, indent=2)
|
1457 |
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, transcript_text)
|
1458 |
updated_content = transcript_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1459 |
|
1460 |
print(f"{kind} 已更新到GCS")
|
1461 |
return gr.update(value=updated_content, interactive=False)
|
@@ -1487,6 +1499,10 @@ def create_LLM_content(video_id, df_string, kind):
|
|
1487 |
content = process_transcript_and_screenshots_on_gcs(video_id)
|
1488 |
update_LLM_content(video_id, content, kind)
|
1489 |
content = json.dumps(content, ensure_ascii=False, indent=2)
|
|
|
|
|
|
|
|
|
1490 |
|
1491 |
return gr.update(value=content, interactive=False)
|
1492 |
|
@@ -2266,6 +2282,15 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2266 |
key_moments_create_button = gr.Button("建立", size="sm", variant="primary")
|
2267 |
with gr.Row():
|
2268 |
key_moments = gr.Textbox(label="Key Moments", lines=40)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2269 |
with gr.Tab("逐字稿"):
|
2270 |
simple_html_content = gr.HTML(label="Simple Transcript")
|
2271 |
with gr.Tab("圖文"):
|
@@ -2354,6 +2379,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2354 |
process_youtube_link_inputs = [password, youtube_link]
|
2355 |
process_youtube_link_outputs = [
|
2356 |
video_id,
|
|
|
2357 |
btn_1,
|
2358 |
btn_2,
|
2359 |
btn_3,
|
@@ -2500,6 +2526,28 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2500 |
inputs=[video_id, key_moments, key_moments_kind],
|
2501 |
outputs=[key_moments]
|
2502 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2503 |
|
2504 |
# 教師版
|
2505 |
worksheet_content_btn.click(
|
|
|
610 |
# 基于逐字稿生成其他所需的输出
|
611 |
source = "gcs"
|
612 |
questions = get_questions(video_id, formatted_simple_transcript, source)
|
613 |
+
questions_json = json.dumps(questions, 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)
|
|
|
633 |
|
634 |
# 确保返回与 UI 组件预期匹配的输出
|
635 |
return video_id, \
|
636 |
+
questions_json, \
|
637 |
questions[0] if len(questions) > 0 else "", \
|
638 |
questions[1] if len(questions) > 1 else "", \
|
639 |
questions[2] if len(questions) > 2 else "", \
|
|
|
1458 |
transcript_text = json.dumps(transcript_json, ensure_ascii=False, indent=2)
|
1459 |
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, transcript_text)
|
1460 |
updated_content = transcript_text
|
1461 |
+
elif kind == "questions":
|
1462 |
+
# from update_LLM_btn -> new_content is a string
|
1463 |
+
# create_LLM_content -> new_content is a list
|
1464 |
+
if isinstance(new_content, str):
|
1465 |
+
questions_json = json.loads(new_content)
|
1466 |
+
else:
|
1467 |
+
questions_json = new_content
|
1468 |
+
questions_text = json.dumps(questions_json, ensure_ascii=False, indent=2)
|
1469 |
+
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, questions_text)
|
1470 |
+
updated_content = questions_text
|
1471 |
|
1472 |
print(f"{kind} 已更新到GCS")
|
1473 |
return gr.update(value=updated_content, interactive=False)
|
|
|
1499 |
content = process_transcript_and_screenshots_on_gcs(video_id)
|
1500 |
update_LLM_content(video_id, content, kind)
|
1501 |
content = json.dumps(content, ensure_ascii=False, indent=2)
|
1502 |
+
elif kind == "questions":
|
1503 |
+
content = generate_questions(df_string)
|
1504 |
+
update_LLM_content(video_id, content, kind)
|
1505 |
+
content = json.dumps(content, ensure_ascii=False, indent=2)
|
1506 |
|
1507 |
return gr.update(value=content, interactive=False)
|
1508 |
|
|
|
2282 |
key_moments_create_button = gr.Button("建立", size="sm", variant="primary")
|
2283 |
with gr.Row():
|
2284 |
key_moments = gr.Textbox(label="Key Moments", lines=40)
|
2285 |
+
with gr.Tab("問題本文"):
|
2286 |
+
with gr.Row() as question_list_admin:
|
2287 |
+
questions_kind = gr.Textbox(value="questions", show_label=False)
|
2288 |
+
questions_edit_button = gr.Button("編輯", size="sm", variant="primary")
|
2289 |
+
questions_update_button = gr.Button("更新", size="sm", variant="primary")
|
2290 |
+
questions_delete_button = gr.Button("刪除", size="sm", variant="primary")
|
2291 |
+
questions_create_button = gr.Button("建立", size="sm", variant="primary")
|
2292 |
+
with gr.Row():
|
2293 |
+
questions_json = gr.Textbox(label="Questions", lines=40)
|
2294 |
with gr.Tab("逐字稿"):
|
2295 |
simple_html_content = gr.HTML(label="Simple Transcript")
|
2296 |
with gr.Tab("圖文"):
|
|
|
2379 |
process_youtube_link_inputs = [password, youtube_link]
|
2380 |
process_youtube_link_outputs = [
|
2381 |
video_id,
|
2382 |
+
questions_json,
|
2383 |
btn_1,
|
2384 |
btn_2,
|
2385 |
btn_3,
|
|
|
2526 |
inputs=[video_id, key_moments, key_moments_kind],
|
2527 |
outputs=[key_moments]
|
2528 |
)
|
2529 |
+
|
2530 |
+
# question_list event
|
2531 |
+
questions_create_button.click(
|
2532 |
+
create_LLM_content,
|
2533 |
+
inputs=[video_id, df_string_output, questions_kind],
|
2534 |
+
outputs=[questions_json]
|
2535 |
+
)
|
2536 |
+
questions_delete_button.click(
|
2537 |
+
delete_LLM_content,
|
2538 |
+
inputs=[video_id, questions_kind],
|
2539 |
+
outputs=[questions_json]
|
2540 |
+
)
|
2541 |
+
questions_edit_button.click(
|
2542 |
+
enable_edit_mode,
|
2543 |
+
inputs=[],
|
2544 |
+
outputs=[questions_json]
|
2545 |
+
)
|
2546 |
+
questions_update_button.click(
|
2547 |
+
update_LLM_content,
|
2548 |
+
inputs=[video_id, questions_json, questions_kind],
|
2549 |
+
outputs=[questions_json]
|
2550 |
+
)
|
2551 |
|
2552 |
# 教師版
|
2553 |
worksheet_content_btn.click(
|