1234565 unmodified lines121314151617181 unmodified line202122232425262728293031323334353637383940414243444546473 unmodified lines515253545556577 unmodified lines65666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541 unmodified line156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423"""图表问答数据集审核系统 - Gradio 5.x 应用用于人工审核每个图表对应的问题和答案是否合理正确"""import gradio as grfrom data_manager import DataManager, data_manager5 unmodified lines# ============== 全局状态 ==============class AppState:"""应用状态管理"""def __init__(self):self.current_source: str = ""self.current_chart_type: str = ""1 unmodified lineself.current_model: str = ""self.all_paths: List[Dict] = []self.current_index: int = -1# 初始化时获取所有路径self.refresh_paths()def refresh_paths(self):"""刷新所有图表路径"""self.all_paths = data_manager.get_all_chart_paths()def get_current_path(self) -> Optional[Dict]:"""获取当前路径信息"""if 0 <= self.current_index < len(self.all_paths):return self.all_paths[self.current_index]return Nonedef set_position(self, source: str, chart_type: str, chart_id: str, model: str):"""设置当前位置"""self.current_source = sourceself.current_chart_type = chart_typeself.current_chart_id = chart_idself.current_model = model# 更新索引for i, path in enumerate(self.all_paths):if (path['source'] == source andpath['chart_type'] == chart_type and3 unmodified linesbreakdef navigate(self, direction: int) -> bool:"""导航到上一个或下一个图表"""new_index = self.current_index + directionif 0 <= new_index < len(self.all_paths):self.current_index = new_index7 unmodified linesstate = AppState()# ============== UI 更新函数 ==============def get_dataset_choices() -> Tuple[List[str], List[str], List[str], List[str]]:"""获取数据集的选择项"""structure = data_manager.get_dataset_structure()sources = list(structure.get('sources', {}).keys())chart_types = []charts = []models = []if state.current_source:source_data = structure['sources'].get(state.current_source, {})chart_types = list(source_data.get('chart_types', {}).keys())if state.current_chart_type:charts = data_manager.get_chart_list(state.current_source, state.current_chart_type)ct_data = source_data.get('chart_types', {}).get(state.current_chart_type, {})models = ct_data.get('models', [])return sources, chart_types, charts, modelsdef update_chart_type_dropdown(source: str):"""更新图表类型下拉框"""state.current_source = sourcestructure = data_manager.get_dataset_structure()chart_types = list(structure.get('sources', {}).get(source, {}).get('chart_types', {}).keys())return gr.Dropdown(choices=chart_types, value=chart_types[0] if chart_types else None)def update_chart_dropdown(source: str, chart_type: str):"""更新图表和模型下拉框"""state.current_source = sourcestate.current_chart_type = chart_typecharts = data_manager.get_chart_list(source, chart_type)structure = data_manager.get_dataset_structure()ct_data = structure.get('sources', {}).get(source, {}).get('chart_types', {}).get(chart_type, {})models = ct_data.get('models', [])return (gr.Dropdown(choices=charts, value=charts[0] if charts else None),gr.Dropdown(choices=models, value=models[0] if models else None))def create_embedded_html(html_content: str, chart_id: str = "") -> str:"""创建嵌入式的 HTML 显示"""if not html_content:return f"""<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:750px;color:#999;border:2px dashed #ddd;border-radius:12px;background:#fafafa;"><div style="font-size:48px;margin-bottom:16px;">📭</div><div style="font-size:18px;font-weight:500;">暂无图表内容</div><div style="font-size:14px;margin-top:8px;">图表 ID: {chart_id or '未知'}</div><div style="font-size:12px;margin-top:16px;color:#888;">请检查数据集目录中是否存在该图表的 HTML 文件</div></div>"""# 使用 base64 编码 HTML 内容,避免引号转义问题html_bytes = html_content.encode('utf-8')html_base64 = base64.b64encode(html_bytes).decode('utf-8')# 增加高度为 750pxiframe_html = f"""<iframesrc="data:text/html;base64,{html_base64}"style="width:100%;height:750px;border:1px solid #e0e0e0;border-radius:8px;background:#fff;"sandbox="allow-scripts allow-same-origin"loading="lazy"></iframe>"""return iframe_htmldef load_chart_data(source: str, chart_type: str, chart_id: str, model: str):"""加载图表数据并返回所有 UI 更新"""if not all([source, chart_type, chart_id, model]):return [create_embedded_html(""), # html_display"### ⚠️ 请在上方选择完整数据路径", # label_info"[]", # qa_data"等待加载数据...", # status_text"请在上方选择图表", # progress_text"{}", # current_qa_reviewsgr.Radio(choices=[], value=None), # qa_selector"" # debug_info]state.set_position(source, chart_type, chart_id, model)chart_data = data_manager.get_chart_data(source, chart_type, chart_id)1 unmodified linelabel_info = chart_data.get('label_info', {})embedded_html = create_embedded_html(html_content, chart_id)debug_info = f"📁 {source}/{chart_type}/{chart_id} | HTML: {len(html_content)} 字符"if label_info:label_text = f"""| 属性 | 值 ||------|-----|| **编号** | {label_info.get('Number', '-')} || **类型** | {label_info.get('Type', '-')} || **来源** | {label_info.get('Source', '-')} || **主题** | {label_info.get('Topic', '-')} || **描述** | {label_info.get('Describe', '-')} || **链接** | [查看原图]({label_info.get('Weblink', '#')}) |"""else:label_text = "⚠️ 暂无标签信息"qa_list = data_manager.get_qa_list(source, chart_type, model, chart_id)existing_reviews = {}for review in data_manager.get_reviews_by_chart(chart_id, model):existing_reviews[review['qa_id']] = reviewprogress_text = f"进度: 当前第 {state.current_index + 1} 个 / 共 {len(state.all_paths)} 个"stats = data_manager.get_review_stats()status_text = f"总览: 已审核 {stats['total']} 笔 | ✅正确: {stats['correct']} | ❌错误: {stats['incorrect']} | ✏️需修改: {stats['needs_modification']}"qa_choices = [f"Q{i+1}: {qa.question[:50]}..." for i, qa in enumerate(qa_list)] if qa_list else []return [embedded_html,label_text,json.dumps([{"id": qa.id, "question": qa.question, "answer": qa.answer} for qa in qa_list]),status_text,progress_text,json.dumps(existing_reviews),gr.Radio(choices=qa_choices, value=qa_choices[0] if qa_choices else None),debug_info]def navigate_prev():"""导航到上一个图表"""if state.navigate(-1):path = state.get_current_path()if path:return (gr.Dropdown(value=path['source']),gr.Dropdown(value=path['chart_type']),gr.Dropdown(value=path['chart_id']),gr.Dropdown(value=path['model']))return [gr.Dropdown(), gr.Dropdown(), gr.Dropdown(), gr.Dropdown()]def navigate_next():"""导航到下一个图表"""if state.navigate(1):path = state.get_current_path()if path:return (gr.Dropdown(value=path['source']),gr.Dropdown(value=path['chart_type']),gr.Dropdown(value=path['chart_id']),gr.Dropdown(value=path['model']))return [gr.Dropdown(), gr.Dropdown(), gr.Dropdown(), gr.Dropdown()]def save_review_handler(qa_id: str, chart_id: str, source: str, chart_type: str, model: str,original_question: str, original_answer: str, status: str,modified_question: str, modified_answer: str, issue_type: str,comment: str, reviewer: str) -> str:"""保存审核记录"""if not qa_id:return "❌ 请先选择一个问答对"review_data = {"qa_id": qa_id, "chart_id": chart_id, "source": source,"chart_type": chart_type, "model": model,"original_question": original_question, "original_answer": original_answer,"status": status, "modified_question": modified_question,"modified_answer": modified_answer, "issue_type": issue_type,"comment": comment, "reviewer": reviewer}data_manager.save_review(review_data)stats = data_manager.get_review_stats()return f"✅ 已保存! 已审核: {stats['total']} | ✅正确: {stats['correct']} | ❌错误: {stats['incorrect']} | ✏️需修改: {stats['needs_modification']}"def export_reviews_handler():"""导出审核记录并返回文件供下载"""# 将文件保存到当前目录output_path = data_manager.export_reviews("./reviews_export.json")# 更新 gr.File 组件使其显示并提供下载return gr.update(value=output_path, visible=True)# ============== 创建 Gradio 界面 ==============def create_ui():# 调整了最小高度为 750px 适配放大后的 iframecustom_css = """.chart-container {min-height: 750px;}.control-panel {background: #f8f9fa;padding: 15px;border-radius: 8px;margin-bottom: 10px;}.debug-panel {font-size: 12px;color: #666;padding: 8px;background: #f5f5f5;border-radius: 4px;margin-top: 10px;}"""with gr.Blocks(title="图表问答数据集审核系统", theme=gr.themes.Soft(), css=custom_css) as app:qa_data_json = gr.State(value="[]")current_reviews_json = gr.State(value="{}")# ==================== 顶部标题与数据导航区 ====================gr.Markdown("# 📊 图表问答数据集审核系统")with gr.Row():status_text = gr.Textbox(value="等待加载数据...", interactive=False, show_label=False, scale=2)progress_text = gr.Textbox(value="请在下方选择图表", interactive=False, show_label=False, scale=1)with gr.Row(elem_classes=["control-panel"]):source_dropdown = gr.Dropdown(label="数据来源 (Source)", choices=[], interactive=True, scale=1)chart_type_dropdown = gr.Dropdown(label="图表类型 (Chart Type)", choices=[], interactive=True, scale=1)chart_dropdown = gr.Dropdown(label="图表 ID", choices=[], interactive=True, scale=1)model_dropdown = gr.Dropdown(label="模型 (Model)", choices=[], interactive=True, scale=1)reviewer_input = gr.Textbox(label="审核人", value="default", interactive=True, scale=1)with gr.Row():prev_btn = gr.Button("⬅️ 上一个图表", variant="secondary")next_btn = gr.Button("➡️ 下一个图表", variant="primary")export_btn = gr.Button("📦 生成并导出审核记录")# 下载文件的容器,默认隐藏,生成后显示download_file = gr.File(label="点击下方链接下载", visible=False)# ==================== 主内容区 (左右并排) ====================with gr.Row():# ===== 左侧:图表展示 (宽度占比 60%) =====with gr.Column(scale=6, min_width=500):gr.Markdown("### 📈 图表展示")html_display = gr.HTML(value="<div style='text-align:center;padding:50px;color:#999;'>请在上方选择完整路径以加载图表</div>",elem_classes=["chart-container"])debug_info = gr.Textbox(label="调试信息", value="", interactive=False, show_label=False, elem_classes=["debug-panel"])# ===== 右侧:标签信息和 QA 审核 (宽度占比 40%) =====with gr.Column(scale=4, min_width=400):# 将元数据折叠,给下方的问答留出更多空间with gr.Accordion("📝 图表标签信息 (Metadata)", open=False):label_display = gr.Markdown(value="暂无信息")gr.Markdown("### ❓ 问答审核")current_qa_id = gr.Textbox(visible=False, value="")qa_selector = gr.Radio(label="1. 选择要审核的问答对", choices=[], interactive=True)qa_question_display = gr.Textbox(label="原始问题", interactive=False, lines=2, value="")qa_answer_display = gr.Textbox(label="原始答案", interactive=False, lines=2, value="")gr.Markdown("---")gr.Markdown("#### 2. 录入审核结果")status_radio = gr.Radio(label="判定结果",choices=[("✅ 正确", "correct"), ("❌ 错误", "incorrect"), ("✏️ 需修改", "needs_modification"), ("⏳ 待定", "pending")],value="pending", interactive=True)issue_type_dropdown = gr.Dropdown(label="问题错误类型 (若有)",choices=["问题歧义", "答案错误", "图表不清晰", "问题不合理", "答案格式错误", "其他"],interactive=True, value="")modified_question = gr.Textbox(label="修改后的问题", placeholder="如需修改问题,请在此输入...", lines=2, interactive=True, value="")modified_answer = gr.Textbox(label="修改后的答案", placeholder="如需修改答案,请在此输入...", lines=2, interactive=True, value="")comment_textbox = gr.Textbox(label="评论/备注", placeholder="请输入审核意见或备注...", lines=2, interactive=True, value="")save_btn = gr.Button("💾 保存当前 QA 审核结果", variant="primary", size="lg")save_result = gr.Textbox(label="", visible=False)# ==================== 事件绑定 ====================def init_dataset():structure = data_manager.get_dataset_structure()sources = list(structure.get('sources', {}).keys())return gr.Dropdown(choices=sources, value=sources[0] if sources else None)app.load(fn=init_dataset, outputs=[source_dropdown])source_dropdown.change(fn=update_chart_type_dropdown, inputs=[source_dropdown], outputs=[chart_type_dropdown])chart_type_dropdown.change(fn=update_chart_dropdown, inputs=[source_dropdown, chart_type_dropdown], outputs=[chart_dropdown, model_dropdown])# 联动加载数据load_inputs = [source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown]load_outputs = [html_display, label_display, qa_data_json, status_text, progress_text, current_reviews_json, qa_selector, debug_info]model_dropdown.change(fn=load_chart_data, inputs=load_inputs, outputs=load_outputs)chart_dropdown.change(fn=load_chart_data, inputs=load_inputs, outputs=load_outputs)# QA 选择器def on_qa_selected(qa_index_str, qa_json, reviews_json):if not qa_index_str or not qa_json:return ["", "", "", gr.Radio(value="pending"), "", "", "", ""]try:qa_list = json.loads(qa_json)reviews = json.loads(reviews_json)index = int(qa_index_str.split(":")[0].replace("Q", "")) - 1qa = qa_list[index]review = reviews.get(qa['id'], {})return [qa['id'], qa['question'], qa['answer'],gr.Radio(value=review.get('status', 'pending')),review.get('issue_type', ''),review.get('modified_question', ''),review.get('modified_answer', ''),review.get('comment', '')]except Exception as e:print(f"Error in on_qa_selected: {e}")return ["", "", "", gr.Radio(value="pending"), "", "", "", ""]qa_selector.change(fn=on_qa_selected,inputs=[qa_selector, qa_data_json, current_reviews_json],outputs=[current_qa_id, qa_question_display, qa_answer_display, status_radio, issue_type_dropdown, modified_question, modified_answer, comment_textbox])prev_btn.click(fn=navigate_prev, outputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown])next_btn.click(fn=navigate_next, outputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown])save_btn.click(fn=save_review_handler,inputs=[current_qa_id, chart_dropdown, source_dropdown, chart_type_dropdown, model_dropdown, qa_question_display, qa_answer_display, status_radio, modified_question, modified_answer, issue_type_dropdown, comment_textbox, reviewer_input],outputs=[save_result]).then(fn=lambda: gr.Textbox(visible=True), outputs=[save_result])# 导出并显示下载文件组件export_btn.click(fn=export_reviews_handler,outputs=[download_file])# ============== 主入口 ==============if __name__ == "__main__":app = create_ui()app.launch(server_name="0.0.0.0",server_port=7860,share=True)123455 unmodified lines1112131415161 unmodified line1819202122232425262728293031323334353637383 unmodified lines4243444546477 unmodified lines55565758596061626364656667686970717273747576777879808182838485868788891 unmodified line919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216"""图表问答数据集审核系统 - Gradio 5.x 应用"""import gradio as grfrom data_manager import DataManager, data_manager5 unmodified lines# ============== 全局状态 ==============class AppState:def __init__(self):self.current_source: str = ""self.current_chart_type: str = ""1 unmodified lineself.current_model: str = ""self.all_paths: List[Dict] = []self.current_index: int = -1self.refresh_paths()def refresh_paths(self):self.all_paths = data_manager.get_all_chart_paths()def get_current_path(self) -> Optional[Dict]:if 0 <= self.current_index < len(self.all_paths):return self.all_paths[self.current_index]return Nonedef set_position(self, source: str, chart_type: str, chart_id: str, model: str):self.current_source = sourceself.current_chart_type = chart_typeself.current_chart_id = chart_idself.current_model = modelfor i, path in enumerate(self.all_paths):if (path['source'] == source andpath['chart_type'] == chart_type and3 unmodified linesbreakdef navigate(self, direction: int) -> bool:new_index = self.current_index + directionif 0 <= new_index < len(self.all_paths):self.current_index = new_index7 unmodified linesstate = AppState()# ============== UI 更新函数 ==============def update_chart_type_dropdown(source: str):state.current_source = sourcestructure = data_manager.get_dataset_structure()chart_types = list(structure.get('sources', {}).get(source, {}).get('chart_types', {}).keys())return gr.Dropdown(choices=chart_types, value=chart_types[0] if chart_types else None)def update_chart_dropdown(source: str, chart_type: str):state.current_source = sourcestate.current_chart_type = chart_typecharts = data_manager.get_chart_list(source, chart_type)structure = data_manager.get_dataset_structure()ct_data = structure.get('sources', {}).get(source, {}).get('chart_types', {}).get(chart_type, {})models = ct_data.get('models', [])return (gr.Dropdown(choices=charts, value=charts[0] if charts else None),gr.Dropdown(choices=models, value=models[0] if models else None))def create_embedded_html(html_content: str, chart_id: str = "") -> str:if not html_content:return f'<div style="display:flex;min-height:750px;align-items:center;justify-content:center;background:#fafafa;border:2px dashed #ddd;">暂无图表内容 (ID: {chart_id})</div>'html_base64 = base64.b64encode(html_content.encode('utf-8')).decode('utf-8')return f'<iframe src="data:text/html;base64,{html_base64}" style="width:100%;height:750px;border:1px solid #e0e0e0;background:#fff;" sandbox="allow-scripts allow-same-origin"></iframe>'def load_chart_data(source: str, chart_type: str, chart_id: str, model: str):if not all([source, chart_type, chart_id, model]):return [create_embedded_html(""), "### 请选择路径", "[]", "等待加载...", "请选择图表", "{}", gr.Radio(choices=[]), ""]state.set_position(source, chart_type, chart_id, model)chart_data = data_manager.get_chart_data(source, chart_type, chart_id)1 unmodified linelabel_info = chart_data.get('label_info', {})embedded_html = create_embedded_html(html_content, chart_id)label_text = f"| 属性 | 值 |\n|---|---|\n" + "\n".join([f"| **{k}** | {v} |" for k, v in label_info.items()])qa_list = data_manager.get_qa_list(source, chart_type, model, chart_id)existing_reviews = {r['qa_id']: r for r in data_manager.get_reviews_by_chart(chart_id, model)}stats = data_manager.get_review_stats()status_msg = f"已审核: {stats['total']} | ✅正确: {stats['correct']} | ❌错误: {stats['incorrect']}"progress_msg = f"进度: {state.current_index + 1} / {len(state.all_paths)}"qa_choices = [f"Q{i+1}: {qa.question[:40]}..." for i, qa in enumerate(qa_list)]return [embedded_html, label_text,json.dumps([{"id": qa.id, "question": qa.question, "answer": qa.answer} for qa in qa_list]),status_msg, progress_msg, json.dumps(existing_reviews),gr.Radio(choices=qa_choices, value=qa_choices[0] if qa_choices else None),f"Path: {source}/{chart_type}/{chart_id}"]def export_reviews_handler():output_path = data_manager.export_reviews("./reviews_export.json")return gr.update(value=output_path, visible=True)# ============== 创建 Gradio 界面 ==============def create_ui():custom_css = ".chart-container { min-height: 750px; } .nav-row { background: #f8f9fa; padding: 10px; border-radius: 8px; }"with gr.Blocks(title="图表问答数据集审核系统", theme=gr.themes.Soft(), css=custom_css) as app:# 内部状态qa_data_json = gr.State(value="[]")current_reviews_json = gr.State(value="{}")gr.Markdown("# 📊 图表问答数据集审核系统")# 顶部导航with gr.Row():status_text = gr.Textbox(label="统计", interactive=False, scale=2)progress_text = gr.Textbox(label="进度", interactive=False, scale=1)with gr.Row(elem_classes=["nav-row"]):source_drop = gr.Dropdown(label="数据来源", choices=[], allow_custom_value=True)type_drop = gr.Dropdown(label="图表类型", choices=[], allow_custom_value=True)id_drop = gr.Dropdown(label="图表 ID", choices=[], allow_custom_value=True)model_drop = gr.Dropdown(label="模型", choices=[], allow_custom_value=True)reviewer = gr.Textbox(label="审核人", value="admin")with gr.Row():prev_btn = gr.Button("⬅️ 上一个")next_btn = gr.Button("➡️ 下一个")export_btn = gr.Button("📦 导出记录", variant="secondary")download_file = gr.File(label="下载导出的 JSON", visible=False)# 主体:左右排版with gr.Row():with gr.Column(scale=6): # 左侧图表html_display = gr.HTML(elem_classes=["chart-container"])debug_info = gr.Markdown()with gr.Column(scale=4): # 右侧审核with gr.Accordion("📝 元数据", open=False):label_display = gr.Markdown()qa_selector = gr.Radio(label="选择问答对")current_qa_id = gr.Textbox(visible=False)orig_q = gr.Textbox(label="原始问题", interactive=False, lines=2)orig_a = gr.Textbox(label="原始答案", interactive=False)gr.Markdown("---")status_radio = gr.Radio(label="判定结果", choices=[("✅ 正确", "correct"), ("❌ 错误", "incorrect"), ("✏️ 需修改", "needs_modification")], value="correct")issue_type = gr.Dropdown(label="错误类型", choices=["答案错误", "问题模糊", "图文不符", "其他"])mod_q = gr.Textbox(label="修改问题", lines=2)mod_a = gr.Textbox(label="修改答案")comment = gr.Textbox(label="备注")save_btn = gr.Button("💾 保存当前审核", variant="primary")save_msg = gr.Textbox(label="系统提示", visible=False)# --- 事件绑定 ---def init_dataset():s = list(data_manager.get_dataset_structure().get('sources', {}).keys())return gr.update(choices=s, value=s[0] if s else None)app.load(fn=init_dataset, outputs=[source_drop])source_drop.change(fn=update_chart_type_dropdown, inputs=[source_drop], outputs=[type_drop])type_drop.change(fn=update_chart_dropdown, inputs=[source_drop, type_drop], outputs=[id_drop, model_drop])load_args = dict(fn=load_chart_data, inputs=[source_drop, type_drop, id_drop, model_drop], outputs=[html_display, label_display, qa_data_json, status_text, progress_text, current_reviews_json, qa_selector, debug_info])id_drop.change(**load_args)model_drop.change(**load_args)def on_qa_select(sel, qa_json, rev_json):if not sel: return [""] * 8qa_list = json.loads(qa_json)revs = json.loads(rev_json)idx = int(sel.split(":")[0][1:]) - 1qa = qa_list[idx]r = revs.get(qa['id'], {})return [qa['id'], qa['question'], qa['answer'], r.get('status', 'correct'), r.get('issue_type', ''), r.get('modified_question', ''), r.get('modified_answer', ''), r.get('comment', '')]qa_selector.change(fn=on_qa_select, inputs=[qa_selector, qa_data_json, current_reviews_json], outputs=[current_qa_id, orig_q, orig_a, status_radio, issue_type, mod_q, mod_a, comment])# 导航nav_out = [source_drop, type_drop, id_drop, model_drop]prev_btn.click(fn=lambda: (state.navigate(-1), *[gr.update(value=v) for v in [state.current_source, state.current_chart_type, state.current_chart_id, state.current_model]])[1:], outputs=nav_out)next_btn.click(fn=lambda: (state.navigate(1), *[gr.update(value=v) for v in [state.current_source, state.current_chart_type, state.current_chart_id, state.current_model]])[1:], outputs=nav_out)save_btn.click(fn=lambda *args: (data_manager.save_review({"qa_id": args[0], "chart_id": args[1], "source": args[2], "chart_type": args[3], "model": args[4],"original_question": args[5], "original_answer": args[6], "status": args[7],"modified_question": args[8], "modified_answer": args[9], "issue_type": args[10],"comment": args[11], "reviewer": args[12]}), "✅ 已保存记录")[1],inputs=[current_qa_id, id_drop, source_drop, type_drop, model_drop, orig_q, orig_a, status_radio, mod_q, mod_a, issue_type, comment, reviewer],outputs=[save_msg]).then(fn=lambda: gr.update(visible=True), outputs=[save_msg])export_btn.click(fn=export_reviews_handler, outputs=[download_file])return app # <--- 关键点:确保在这里 returnif __name__ == "__main__":app = create_ui()app.launch(server_name="0.0.0.0", server_port=7860)
app.py+85-292