Files changed (3)
- README.md+161-2
- app.py+140-207
- requirements.txt+1-1
3 unmodified lines45678910113 unmodified linescolorFrom: bluecolorTo: purplesdk: gradiosdk_version: "4.44.0"python_version: "3.10"app_file: app.pypinned: false---3 unmodified lines4567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691703 unmodified linescolorFrom: bluecolorTo: purplesdk: gradiosdk_version: "5.9.1"python_version: "3.10"app_file: app.pypinned: false---# 📊 图表问答数据集审核系统一个基于 Gradio 的人工审核系统,用于审核图表问答数据集中的问题和答案是否合理正确。## 功能特点- 📊 **图表展示**:支持 HTML 格式的交互式图表展示- 📁 **目录导航**:按 Source → Chart Type → Chart → Model 层级浏览- ✅ **审核操作**:支持正确、错误、需修改、待定四种状态- ✏️ **内容编辑**:可修改问题和答案,添加评论备注- 📈 **统计面板**:实时显示审核进度和统计信息- 📥 **数据导出**:一键导出审核记录为 JSON 格式- ⌨️ **快捷键**:支持键盘导航和状态选择## 目录结构```project/├── app.py # 主应用├── data_manager.py # 数据管理模块├── requirements.txt # 依赖列表│├── dataset/ # 数据集目录(需要自行放置)│ ├── web/ # 图表 HTML 文件│ │ └── {source}/│ │ └── {chart_type}/│ │ └── *.html│ ├── label/ # 图表标签信息│ │ └── {source}/│ │ └── {chart_type}/│ │ └── *.json│ └── question_answer/ # QA 数据│ └── {source}/│ └── {chart_type}/│ └── {model}/│ └── *.json│└── reviews/ # 审核记录(自动创建)└── reviews.json```## 数据格式### Label JSON 格式```json{"Number": "0001","Type": "bar","Source": "Apache Echarts","Weblink": "https://example.com/chart","Topic": "Weather Statistics by City","Describe": "The chart compares...","Other": ""}```### QA JSON 格式```json{"id": "chart_0001_bar_q1","chart": "chart_0001_bar","question": "Weather Statistics图表中,三个城市在Showers天气下的总天数是多少?","answer": "203"}```### 审核记录格式```json{"review_id": "uuid","chart_id": "chart_0001_bar","qa_id": "chart_0001_bar_q1","source": "Apache Echarts","chart_type": "bar","model": "gpt-4","original_question": "...","original_answer": "...","status": "correct","modified_question": "","modified_answer": "","issue_type": "","comment": "","reviewer": "default","review_time": "2024-01-01T00:00:00"}```## 快速开始### 1. 安装依赖```bashpip install -r requirements.txt```### 2. 准备数据集将你的数据集放置到 `dataset/` 目录下,按照上述目录结构组织。### 3. 启动应用```bashpython app.py```应用将在 `http://localhost:7860` 启动。## 快捷键| 按键 | 功能 ||------|------|| ← | 上一个图表 || → | 下一个图表 || 1 | 标记为正确 || 2 | 标记为错误 || 3 | 标记为需修改 || 4 | 标记为待定 |## 部署到 Hugging Face Spaces### 方法 1:通过网页界面上传1. 在 Hugging Face 创建一个新的 Space2. 上传所有文件:`app.py`、`data_manager.py`、`requirements.txt`、`README.md`3. 在 Files 标签页创建 `dataset/` 目录结构4. 上传你的数据集文件### 方法 2:通过 Git 推送```bash# 克隆 Spacegit clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAMEcd YOUR_SPACE_NAME# 复制项目文件cp /path/to/app.py .cp /path/to/data_manager.py .cp /path/to/requirements.txt .cp /path/to/README.md .# 创建数据集目录并上传数据mkdir -p dataset/web dataset/label dataset/question_answer# 提交并推送git add .git commit -m "Initial commit"git push```## 注意事项- 免费版 Spaces 有存储限制- Spaces 重启后审核记录会丢失,请定期导出- 大数据集建议使用 Hugging Face Datasets 存储## 许可证MIT License
1234591 unmodified lines9798991001011021033 unmodified lines10710810911011111211320 unmodified lines13413513613713813914014114214336 unmodified lines18018118218318418518618718818919019119241 unmodified lines23423523623723823931 unmodified lines2712722732742752762771 unmodified line2792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283292 unmodified lines3323333343353363373383393403413423433443453462 unmodified lines34935035135235335435537 unmodified lines39339439539639739839940028 unmodified lines42943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651723 unmodified lines54154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960043 unmodified lines644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684"""图表问答数据集审核系统 - Gradio 应用用于人工审核每个图表对应的问题和答案是否合理正确"""import gradio as gr91 unmodified linesreturn sources, chart_types, charts, modelsdef update_chart_type_dropdown(source: str) -> gr.Dropdown:"""更新图表类型下拉框"""state.current_source = sourcestructure = data_manager.get_dataset_structure()3 unmodified linesreturn gr.Dropdown(choices=chart_types, value=chart_types[0] if chart_types else None)def update_chart_dropdown(source: str, chart_type: str) -> Tuple[gr.Dropdown, gr.Dropdown]:"""更新图表和模型下拉框"""state.current_source = sourcestate.current_chart_type = chart_type20 unmodified linesreturn ["", # html_display"", # label_info[], # qa_data"", # status_text"请在左侧选择图表", # progress_textgr.State({}) # current_qa_reviews]# 更新状态36 unmodified linesstats = data_manager.get_review_stats()status_text = f"已审核: {stats['total']} | ✅正确: {stats['correct']} | ❌错误: {stats['incorrect']} | ✏️需修改: {stats['needs_modification']}"return [html_content, # html_displaylabel_text, # label_infoqa_list, # qa_data (for state)status_text, # status_textprogress_text, # progress_textexisting_reviews # current_qa_reviews]41 unmodified linesreviewer: str) -> str:"""保存审核记录"""review_data = {"qa_id": qa_id,"chart_id": chart_id,31 unmodified lines# 自定义 CSScustom_css = """.chart-container {height: 600px;overflow: auto;border: 1px solid #e0e0e0;border-radius: 8px;1 unmodified linebackground: #fafafa;}.qa-item {border: 1px solid #e0e0e0;border-radius: 8px;padding: 15px;margin-bottom: 15px;background: white;}.qa-question {font-weight: bold;color: #1a73e8;margin-bottom: 8px;}.qa-answer {color: #0d652d;padding: 8px;background: #e8f5e9;border-radius: 4px;margin-bottom: 10px;}.status-correct { background-color: #d4edda !important; border-color: #c3e6cb !important; }.status-incorrect { background-color: #f8d7da !important; border-color: #f5c6cb !important; }.status-needs-modification { background-color: #fff3cd !important; border-color: #ffeeba !important; }.status-pending { background-color: #e2e3e5 !important; border-color: #d6d8db !important; }.control-panel {background: #f8f9fa;padding: 15px;border-radius: 8px;margin-bottom: 10px;}.stats-panel {background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);color: white;padding: 15px;border-radius: 8px;margin-bottom: 15px;}.nav-button {min-width: 120px;}"""with gr.Blocks(2 unmodified linescss=custom_css) as app:# 隐藏的状态存储current_qa_reviews = gr.State({})qa_data_state = gr.State([])# ==================== 标题栏 ====================gr.Markdown("""# 📊 图表问答数据集审核系统审核每个图表对���的问题和答案是否合理正确。使用 ← → 按钮或键盘方向键切换图表。""")# ==================== 顶部状态栏 ====================2 unmodified lineslabel="审核统计",value="等待加载数据...",interactive=False,show_label=False)progress_text = gr.Textbox(label="进度",37 unmodified lines# 导航按钮with gr.Row():prev_btn = gr.Button("⬅️ 上一个", elem_classes=["nav-button"])next_btn = gr.Button("➡️ 下一个", elem_classes=["nav-button"])# 导出按钮export_btn = gr.Button("📥 导出审核记录", variant="secondary")28 unmodified lines# QA 审核区gr.Markdown("### ❓ 问答审核")# 审核面板 (动态生成)with gr.Column(visible=True) as review_panel:# 当前选中的 QA 信息(隐藏)current_qa_id = gr.Textbox(visible=False)current_qa_question = gr.Textbox(visible=False)current_qa_answer = gr.Textbox(visible=False)# QA 显示qa_question_display = gr.Textbox(label="问题",interactive=False,lines=2)qa_answer_display = gr.Textbox(label="答案",interactive=False,lines=1)# QA 选择器qa_selector = gr.Radio(label="选择要审核的问答对",choices=[],interactive=True)gr.Markdown("---")gr.Markdown("#### 审核操作")# 审核状态选择status_radio = gr.Radio(label="审核状态",choices=[("✅ 正确", "correct"),("❌ 错误", "incorrect"),("✏️ 需修改", "needs_modification"),("⏳ 待定", "pending")],value="pending",interactive=True)# 问题类型(仅在选择错误或需修改时显示)issue_type_dropdown = gr.Dropdown(label="问题类型",choices=["问题歧义","答案错误","图表不清晰","问题不合理","答案格式错误","其他"],interactive=True,visible=True)# 修改后的问题和答案modified_question = gr.Textbox(label="修改后的问题",placeholder="如需修改问题,请在此输入...",lines=2,interactive=True)modified_answer = gr.Textbox(label="修改后的答案",placeholder="如需修改答案,请在此输入...",lines=1,interactive=True)# 评论comment_textbox = gr.Textbox(label="评论/备注",placeholder="请输入审核意见或备注...",lines=2,interactive=True)# 保存按钮save_btn = gr.Button("💾 保存审核结果", variant="primary")save_result = gr.Textbox(label="", visible=False)# ==================== 事件绑定 ====================23 unmodified lines)# 选择图表 -> 加载数据def on_chart_selected(source, chart_type, chart_id, model):results = load_chart_data(source, chart_type, chart_id, model)# 更新 QA 选择器qa_list = results[2] # qa_dataqa_choices = [f"Q{i+1}: {qa.question[:50]}..." for i, qa in enumerate(qa_list)] if qa_list else []return results + [gr.Radio(choices=qa_choices, value=qa_choices[0] if qa_choices else None)]model_dropdown.change(fn=on_chart_selected,inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],outputs=[html_display, label_display, qa_data_state, status_text, progress_text,current_qa_reviews, qa_selector])chart_dropdown.change(fn=on_chart_selected,inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],outputs=[html_display, label_display, qa_data_state, status_text, progress_text,current_qa_reviews, qa_selector])# QA 选择器变化 -> 更新审核面板def on_qa_selected(qa_index_str, qa_list, existing_reviews):if not qa_index_str or not qa_list:return [""] * 3 + [gr.Radio(value="pending"), "", "", "", ""]# 解析索引try:index = int(qa_index_str.split(":")[0].replace("Q", "")) - 1qa = qa_list[index]except:return [""] * 3 + [gr.Radio(value="pending"), "", "", "", ""]# 检查是否有现有审核review = existing_reviews.get(qa.id, {})return [qa.id, # current_qa_idqa.question, # qa_question_displayqa.answer, # qa_answer_displaygr.Radio(value=review.get('status', 'pending')), # status_radioreview.get('issue_type', ''), # issue_type_dropdownreview.get('modified_question', ''), # modified_questionreview.get('modified_answer', ''), # modified_answerreview.get('comment', '') # comment_textbox]qa_selector.change(fn=on_qa_selected,inputs=[qa_selector, qa_data_state, current_qa_reviews],outputs=[current_qa_id, qa_question_display, qa_answer_display,status_radio, issue_type_dropdown, modified_question, modified_answer, comment_textbox43 unmodified linesfn=lambda: gr.Textbox(visible=True),outputs=[export_result])# 键盘快捷键app.load(fn=lambda: None,js="""() => {document.addEventListener('keydown', (e) => {if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;if (e.key === 'ArrowLeft') {document.querySelector('button:has(.nav-button)')?.click();// 模拟点击上一个按钮const prevBtn = Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('上一个'));if (prevBtn) prevBtn.click();}if (e.key === 'ArrowRight') {const nextBtn = Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('下一个'));if (nextBtn) nextBtn.click();}if (e.key === '1') {document.querySelector('input[value="correct"]')?.click();}if (e.key === '2') {document.querySelector('input[value="incorrect"]')?.click();}if (e.key === '3') {document.querySelector('input[value="needs_modification"]')?.click();}if (e.key === '4') {document.querySelector('input[value="pending"]')?.click();}});}""")return app1234591 unmodified lines9798991001011021033 unmodified lines10710810911011111211320 unmodified lines13413513613713813914014114214314436 unmodified lines18118218318418518618718818919019119219319419519619741 unmodified lines23924024124224324424524624731 unmodified lines2792802812822832842851 unmodified line2872882892902912922932942952962972982 unmodified lines3013023033043053063073083093103113123133143152 unmodified lines31831932032132232332432537 unmodified lines36336436536636736836937028 unmodified lines39940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748823 unmodified lines51251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756843 unmodified lines612613614615616617"""图表问答数据集审核系统 - Gradio 5.x 应用用于人工审核每个图表对应的问题和答案是否合理正确"""import gradio as gr91 unmodified linesreturn sources, chart_types, charts, modelsdef update_chart_type_dropdown(source: str):"""更新图表类型下拉框"""state.current_source = sourcestructure = data_manager.get_dataset_structure()3 unmodified linesreturn 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_type20 unmodified linesreturn ["", # html_display"", # label_info"[]", # qa_data (JSON string)"等待加载数据...", # status_text"请在左侧选择图表", # progress_text"{}", # current_qa_reviews (JSON string)gr.Radio(choices=[], value=None) # qa_selector]# 更新状态36 unmodified linesstats = data_manager.get_review_stats()status_text = f"已审核: {stats['total']} | ✅正确: {stats['correct']} | ❌错误: {stats['incorrect']} | ✏️需修改: {stats['needs_modification']}"# QA 选择器选项qa_choices = [f"Q{i+1}: {qa.question[:50]}..." for i, qa in enumerate(qa_list)] if qa_list else []return [html_content, # html_displaylabel_text, # label_infojson.dumps([{"id": qa.id, "question": qa.question, "answer": qa.answer} for qa in qa_list]), # qa_data (JSON string)status_text, # status_textprogress_text, # progress_textjson.dumps(existing_reviews), # current_qa_reviews (JSON string)gr.Radio(choices=qa_choices, value=qa_choices[0] if qa_choices else None) # qa_selector]41 unmodified linesreviewer: str) -> str:"""保存审核记录"""if not qa_id:return "❌ 请先选择一个问答对"review_data = {"qa_id": qa_id,"chart_id": chart_id,31 unmodified lines# 自定义 CSScustom_css = """.chart-container {height: 500px;overflow: auto;border: 1px solid #e0e0e0;border-radius: 8px;1 unmodified linebackground: #fafafa;}.control-panel {background: #f8f9fa;padding: 15px;border-radius: 8px;margin-bottom: 10px;}"""with gr.Blocks(2 unmodified linescss=custom_css) as app:# 隐藏的状态存储(使用 JSON 字符串)qa_data_json = gr.State(value="[]")current_reviews_json = gr.State(value="{}")# ==================== 标题栏 ====================gr.Markdown("""# 📊 图表问答数据集审核系统审核每个图表对应的问题和答案是否合理正确。使用 ← → 按钮切换图表。""")# ==================== 顶部状态栏 ====================2 unmodified lineslabel="审核统计",value="等待加载数据...",interactive=False,show_label=False,scale=2)progress_text = gr.Textbox(label="进度",37 unmodified lines# 导航按钮with gr.Row():prev_btn = gr.Button("⬅️ 上一个")next_btn = gr.Button("➡️ 下一个")# 导出按钮export_btn = gr.Button("📥 导出审核记录", variant="secondary")28 unmodified lines# QA 审核区gr.Markdown("### ❓ 问答审核")# 当前选中的 QA 信息(隐藏)current_qa_id = gr.Textbox(visible=False, value="")# QA 显示qa_question_display = gr.Textbox(label="问题",interactive=False,lines=2,value="")qa_answer_display = gr.Textbox(label="答案",interactive=False,lines=1,value="")# QA 选择器qa_selector = gr.Radio(label="选择要审核的问答对",choices=[],interactive=True)gr.Markdown("---")gr.Markdown("#### 审核操作")# 审核状态选择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=1,interactive=True,value="")# 评论comment_textbox = gr.Textbox(label="评论/备注",placeholder="请输入审核意见或备注...",lines=2,interactive=True,value="")# 保存按钮save_btn = gr.Button("💾 保存审核结果", variant="primary")save_result = gr.Textbox(label="", visible=False)# ==================== 事件绑定 ====================23 unmodified lines)# 选择图表 -> 加载数据model_dropdown.change(fn=load_chart_data,inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],outputs=[html_display, label_display, qa_data_json, status_text, progress_text,current_reviews_json, qa_selector])chart_dropdown.change(fn=load_chart_data,inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],outputs=[html_display, label_display, qa_data_json, status_text, progress_text,current_reviews_json, qa_selector])# 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'], # current_qa_idqa['question'], # qa_question_displayqa['answer'], # qa_answer_displaygr.Radio(value=review.get('status', 'pending')), # status_radioreview.get('issue_type', ''), # issue_type_dropdownreview.get('modified_question', ''), # modified_questionreview.get('modified_answer', ''), # modified_answerreview.get('comment', '') # comment_textbox]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_textbox43 unmodified linesfn=lambda: gr.Textbox(visible=True),outputs=[export_result])return app
1234# Gradio 审核系统依赖gradio>=4.0.0python-multipart>=0.0.61234# Gradio 审核系统依赖gradio>=5.0.0python-multipart>=0.0.6
README.md+161-2
app.py+140-207
requirements.txt+1-1