Spaces:
Sleeping
Sleeping
def get_mind_map_html(mind_map):
Browse files
app.py
CHANGED
|
@@ -349,6 +349,7 @@ def process_youtube_link(link):
|
|
| 349 |
first_text = formatted_transcript[0]['text']
|
| 350 |
mind_map_json = get_mind_map(video_id, formatted_simple_transcript)
|
| 351 |
mind_map = mind_map_json["mind_map"]
|
|
|
|
| 352 |
|
| 353 |
# 确保返回与 UI 组件预期匹配的输出
|
| 354 |
return questions[0] if len(questions) > 0 else "", \
|
|
@@ -357,6 +358,7 @@ def process_youtube_link(link):
|
|
| 357 |
formatted_transcript_json, \
|
| 358 |
summary, \
|
| 359 |
mind_map, \
|
|
|
|
| 360 |
html_content, \
|
| 361 |
first_image, \
|
| 362 |
first_text,
|
|
@@ -458,6 +460,18 @@ def generate_mind_map(df_string):
|
|
| 458 |
|
| 459 |
return mind_map
|
| 460 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
def processed_video_summary_to_json(summary):
|
| 462 |
"""
|
| 463 |
整體格式為:
|
|
@@ -797,7 +811,20 @@ def next_slide():
|
|
| 797 |
def get_video_id():
|
| 798 |
return VIDEO_ID
|
| 799 |
|
| 800 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
with gr.Row():
|
| 802 |
with gr.Column():
|
| 803 |
file_upload = gr.File(label="Upload your CSV or Word file", visible=False)
|
|
@@ -832,6 +859,7 @@ with gr.Blocks() as demo:
|
|
| 832 |
btn_create_question = gr.Button("Create Questions")
|
| 833 |
with gr.Tab("心智圖"):
|
| 834 |
mind_map = gr.Textbox()
|
|
|
|
| 835 |
|
| 836 |
send_button.click(
|
| 837 |
respond,
|
|
@@ -849,7 +877,22 @@ with gr.Blocks() as demo:
|
|
| 849 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
| 850 |
|
| 851 |
# 当输入 YouTube 链接时触发
|
| 852 |
-
youtube_link.change(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 853 |
|
| 854 |
# 当输入网页链接时触发
|
| 855 |
web_link.change(process_web_link, inputs=web_link, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
|
|
|
| 349 |
first_text = formatted_transcript[0]['text']
|
| 350 |
mind_map_json = get_mind_map(video_id, formatted_simple_transcript)
|
| 351 |
mind_map = mind_map_json["mind_map"]
|
| 352 |
+
mind_map_html = get_mind_map_html(mind_map)
|
| 353 |
|
| 354 |
# 确保返回与 UI 组件预期匹配的输出
|
| 355 |
return questions[0] if len(questions) > 0 else "", \
|
|
|
|
| 358 |
formatted_transcript_json, \
|
| 359 |
summary, \
|
| 360 |
mind_map, \
|
| 361 |
+
mind_map_html, \
|
| 362 |
html_content, \
|
| 363 |
first_image, \
|
| 364 |
first_text,
|
|
|
|
| 460 |
|
| 461 |
return mind_map
|
| 462 |
|
| 463 |
+
def get_mind_map_html(mind_map):
|
| 464 |
+
mind_map.replace("```markdown", "").replace("```", "")
|
| 465 |
+
|
| 466 |
+
mind_map_html = f"""
|
| 467 |
+
<div class="markmap">
|
| 468 |
+
<script type="text/template">
|
| 469 |
+
{mind_map}
|
| 470 |
+
</script>
|
| 471 |
+
</div>
|
| 472 |
+
"""
|
| 473 |
+
return mind_map_html
|
| 474 |
+
|
| 475 |
def processed_video_summary_to_json(summary):
|
| 476 |
"""
|
| 477 |
整體格式為:
|
|
|
|
| 811 |
def get_video_id():
|
| 812 |
return VIDEO_ID
|
| 813 |
|
| 814 |
+
HEAD = """
|
| 815 |
+
<meta charset="UTF-8">
|
| 816 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 817 |
+
<style>
|
| 818 |
+
svg.markmap {{
|
| 819 |
+
width: 100%;
|
| 820 |
+
height: 100vh;
|
| 821 |
+
}}
|
| 822 |
+
</style>
|
| 823 |
+
<script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@0.15.2"></script>
|
| 824 |
+
"""
|
| 825 |
+
|
| 826 |
+
|
| 827 |
+
with gr.Blocks(head=HEAD) as demo:
|
| 828 |
with gr.Row():
|
| 829 |
with gr.Column():
|
| 830 |
file_upload = gr.File(label="Upload your CSV or Word file", visible=False)
|
|
|
|
| 859 |
btn_create_question = gr.Button("Create Questions")
|
| 860 |
with gr.Tab("心智圖"):
|
| 861 |
mind_map = gr.Textbox()
|
| 862 |
+
mind_map_html = gr.HTML()
|
| 863 |
|
| 864 |
send_button.click(
|
| 865 |
respond,
|
|
|
|
| 877 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
| 878 |
|
| 879 |
# 当输入 YouTube 链接时触发
|
| 880 |
+
youtube_link.change(
|
| 881 |
+
process_youtube_link,
|
| 882 |
+
inputs=youtube_link,
|
| 883 |
+
outputs=[
|
| 884 |
+
btn_1,
|
| 885 |
+
btn_2,
|
| 886 |
+
btn_3,
|
| 887 |
+
df_string_output,
|
| 888 |
+
df_summarise,
|
| 889 |
+
mind_map,
|
| 890 |
+
mind_map_html,
|
| 891 |
+
transcript_html,
|
| 892 |
+
slide_image,
|
| 893 |
+
slide_text
|
| 894 |
+
]
|
| 895 |
+
)
|
| 896 |
|
| 897 |
# 当输入网页链接时触发
|
| 898 |
web_link.change(process_web_link, inputs=web_link, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|