Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # --- Init params --- | |
| def init_params(text, request: gr.Request): | |
| youtube_link = "" | |
| password_text = "" | |
| block_ready_flag = "READY" | |
| admin = gr.update(visible=True) | |
| return admin, password_text, youtube_link, block_ready_flag | |
| HEAD = """ | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <style> | |
| svg.markmap {{ | |
| width: 100%; | |
| height: 100vh; | |
| }} | |
| </style> | |
| <script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@0.15.2"></script> | |
| <script> | |
| const mind_map_tab_button = document.querySelector("#mind_map_tab-button"); | |
| if (mind_map_tab_button) { | |
| mind_map_tab_button.addEventListener('click', function() { | |
| const mind_map_markdown = document.querySelector("#mind_map_markdown > label > textarea"); | |
| if (mind_map_markdown) { | |
| // 当按钮被点击时,打印当前的textarea的值 | |
| console.log('Value changed to: ' + mind_map_markdown.value); | |
| markmap.autoLoader.renderAll(); | |
| } | |
| }); | |
| } | |
| </script> | |
| """ | |
| with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, secondary_hue=gr.themes.colors.amber, text_size = gr.themes.sizes.text_lg), head=HEAD) as demo: | |
| with gr.Row() as admin: | |
| password = gr.Textbox(label="Password", type="password", elem_id="password_input", visible=True) | |
| youtube_link = gr.Textbox(label="Enter YouTube Link", elem_id="youtube_link_input", visible=True) | |
| video_id = gr.Textbox(label="video_id", visible=True) | |
| # file_upload = gr.File(label="Upload your CSV or Word file", visible=False) | |
| # web_link = gr.Textbox(label="Enter Web Page Link", visible=False) | |
| user_data = gr.Textbox(label="User Data", elem_id="user_data_input", visible=True) | |
| block_ready_flag = gr.Textbox(label="load_ready_flag", elem_id="block_ready_flag", value="LOADING", visible=True) | |
| youtube_link_btn = gr.Button("Submit_YouTube_Link", elem_id="youtube_link_btn", visible=True) | |
| with gr.Row() as data_state: | |
| content_subject_state = gr.State() # 使用 gr.State 存储 content_subject | |
| # init_params | |
| init_outputs = [ | |
| admin, | |
| password, | |
| youtube_link, | |
| block_ready_flag, | |
| ] | |
| demo.load( | |
| init_params, | |
| inputs =[youtube_link], | |
| outputs = init_outputs | |
| ) | |
| block_ready_flag.visible = False | |
| demo.launch(allowed_paths=["videos"], server_name="0.0.0.0", server_port=7860) | |