- README.md +161 -2
- app.py +140 -207
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -4,8 +4,167 @@ emoji: 📊
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: "
|
| 8 |
python_version: "3.10"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: "5.9.1"
|
| 8 |
python_version: "3.10"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# 📊 图表问答数据集审核系统
|
| 14 |
+
|
| 15 |
+
一个基于 Gradio 的人工审核系统,用于审核图表问答数据集中的问题和答案是否合理正确。
|
| 16 |
+
|
| 17 |
+
## 功能特点
|
| 18 |
+
|
| 19 |
+
- 📊 **图表展示**:支持 HTML 格式的交互式图表展示
|
| 20 |
+
- 📁 **目录导航**:按 Source → Chart Type → Chart → Model 层级浏览
|
| 21 |
+
- ✅ **审核操作**:支持正确、错误、需修改、待定四种状态
|
| 22 |
+
- ✏️ **内容编辑**:可修改问题和答案,添加评论备注
|
| 23 |
+
- 📈 **统计面板**:实时显示审核进度和统计信息
|
| 24 |
+
- 📥 **数据导出**:一键导出审核记录为 JSON 格式
|
| 25 |
+
- ⌨️ **快捷键**:支持键盘导航和状态选择
|
| 26 |
+
|
| 27 |
+
## 目录结构
|
| 28 |
+
|
| 29 |
+
```
|
| 30 |
+
project/
|
| 31 |
+
├── app.py # 主应用
|
| 32 |
+
├── data_manager.py # 数据管理模块
|
| 33 |
+
├── requirements.txt # 依赖列表
|
| 34 |
+
│
|
| 35 |
+
├── dataset/ # 数据集目录(需要自行放置)
|
| 36 |
+
│ ├── web/ # 图表 HTML 文件
|
| 37 |
+
│ │ └── {source}/
|
| 38 |
+
│ │ └── {chart_type}/
|
| 39 |
+
│ │ └── *.html
|
| 40 |
+
│ ├── label/ # 图表标签信息
|
| 41 |
+
│ │ └── {source}/
|
| 42 |
+
│ │ └── {chart_type}/
|
| 43 |
+
│ │ └── *.json
|
| 44 |
+
│ └── question_answer/ # QA 数据
|
| 45 |
+
│ └── {source}/
|
| 46 |
+
│ └── {chart_type}/
|
| 47 |
+
│ └── {model}/
|
| 48 |
+
│ └── *.json
|
| 49 |
+
│
|
| 50 |
+
└── reviews/ # 审核记录(自动创建)
|
| 51 |
+
└── reviews.json
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## 数据格式
|
| 55 |
+
|
| 56 |
+
### Label JSON 格式
|
| 57 |
+
```json
|
| 58 |
+
{
|
| 59 |
+
"Number": "0001",
|
| 60 |
+
"Type": "bar",
|
| 61 |
+
"Source": "Apache Echarts",
|
| 62 |
+
"Weblink": "https://example.com/chart",
|
| 63 |
+
"Topic": "Weather Statistics by City",
|
| 64 |
+
"Describe": "The chart compares...",
|
| 65 |
+
"Other": ""
|
| 66 |
+
}
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### QA JSON 格式
|
| 70 |
+
```json
|
| 71 |
+
{
|
| 72 |
+
"id": "chart_0001_bar_q1",
|
| 73 |
+
"chart": "chart_0001_bar",
|
| 74 |
+
"question": "Weather Statistics图表中,三个城市在Showers天气下的总天数是多少?",
|
| 75 |
+
"answer": "203"
|
| 76 |
+
}
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### 审核记录格式
|
| 80 |
+
```json
|
| 81 |
+
{
|
| 82 |
+
"review_id": "uuid",
|
| 83 |
+
"chart_id": "chart_0001_bar",
|
| 84 |
+
"qa_id": "chart_0001_bar_q1",
|
| 85 |
+
"source": "Apache Echarts",
|
| 86 |
+
"chart_type": "bar",
|
| 87 |
+
"model": "gpt-4",
|
| 88 |
+
"original_question": "...",
|
| 89 |
+
"original_answer": "...",
|
| 90 |
+
"status": "correct",
|
| 91 |
+
"modified_question": "",
|
| 92 |
+
"modified_answer": "",
|
| 93 |
+
"issue_type": "",
|
| 94 |
+
"comment": "",
|
| 95 |
+
"reviewer": "default",
|
| 96 |
+
"review_time": "2024-01-01T00:00:00"
|
| 97 |
+
}
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
## 快速开始
|
| 101 |
+
|
| 102 |
+
### 1. 安装依赖
|
| 103 |
+
|
| 104 |
+
```bash
|
| 105 |
+
pip install -r requirements.txt
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### 2. 准备数据集
|
| 109 |
+
|
| 110 |
+
将你的数据集放置到 `dataset/` 目录下,按照上述目录结构组织。
|
| 111 |
+
|
| 112 |
+
### 3. 启动应用
|
| 113 |
+
|
| 114 |
+
```bash
|
| 115 |
+
python app.py
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
应用将在 `http://localhost:7860` 启动。
|
| 119 |
+
|
| 120 |
+
## 快捷键
|
| 121 |
+
|
| 122 |
+
| 按键 | 功能 |
|
| 123 |
+
|------|------|
|
| 124 |
+
| ← | 上一个图表 |
|
| 125 |
+
| → | 下一个图表 |
|
| 126 |
+
| 1 | 标记为正确 |
|
| 127 |
+
| 2 | 标记为错误 |
|
| 128 |
+
| 3 | 标记为需修改 |
|
| 129 |
+
| 4 | 标记为待定 |
|
| 130 |
+
|
| 131 |
+
## 部署到 Hugging Face Spaces
|
| 132 |
+
|
| 133 |
+
### 方法 1:通过网页界面上传
|
| 134 |
+
|
| 135 |
+
1. 在 Hugging Face 创建一个新的 Space
|
| 136 |
+
2. 上传所有文件:`app.py`、`data_manager.py`、`requirements.txt`、`README.md`
|
| 137 |
+
3. 在 Files 标签页创建 `dataset/` 目录结构
|
| 138 |
+
4. 上传你的数据集文件
|
| 139 |
+
|
| 140 |
+
### 方法 2:通过 Git 推送
|
| 141 |
+
|
| 142 |
+
```bash
|
| 143 |
+
# 克隆 Space
|
| 144 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
|
| 145 |
+
cd YOUR_SPACE_NAME
|
| 146 |
+
|
| 147 |
+
# 复制项目文件
|
| 148 |
+
cp /path/to/app.py .
|
| 149 |
+
cp /path/to/data_manager.py .
|
| 150 |
+
cp /path/to/requirements.txt .
|
| 151 |
+
cp /path/to/README.md .
|
| 152 |
+
|
| 153 |
+
# 创建数据集目录并上传数据
|
| 154 |
+
mkdir -p dataset/web dataset/label dataset/question_answer
|
| 155 |
+
|
| 156 |
+
# 提交并推送
|
| 157 |
+
git add .
|
| 158 |
+
git commit -m "Initial commit"
|
| 159 |
+
git push
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
## 注意事项
|
| 163 |
+
|
| 164 |
+
- 免费版 Spaces 有存储限制
|
| 165 |
+
- Spaces 重启后审核记录会丢失,请定期导出
|
| 166 |
+
- 大数据集建议使用 Hugging Face Datasets 存储
|
| 167 |
+
|
| 168 |
+
## 许可证
|
| 169 |
+
|
| 170 |
+
MIT License
|
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
图表问答数据集审核系统 - Gradio 应用
|
| 3 |
用于人工审核每个图表对应的问题和答案是否合理正确
|
| 4 |
"""
|
| 5 |
import gradio as gr
|
|
@@ -97,7 +97,7 @@ def get_dataset_choices() -> Tuple[List[str], List[str], List[str], List[str]]:
|
|
| 97 |
return sources, chart_types, charts, models
|
| 98 |
|
| 99 |
|
| 100 |
-
def update_chart_type_dropdown(source: str)
|
| 101 |
"""更新图表类型下拉框"""
|
| 102 |
state.current_source = source
|
| 103 |
structure = data_manager.get_dataset_structure()
|
|
@@ -107,7 +107,7 @@ def update_chart_type_dropdown(source: str) -> gr.Dropdown:
|
|
| 107 |
return gr.Dropdown(choices=chart_types, value=chart_types[0] if chart_types else None)
|
| 108 |
|
| 109 |
|
| 110 |
-
def update_chart_dropdown(source: str, chart_type: str)
|
| 111 |
"""更新图表和模型下拉框"""
|
| 112 |
state.current_source = source
|
| 113 |
state.current_chart_type = chart_type
|
|
@@ -134,10 +134,11 @@ def load_chart_data(source: str, chart_type: str, chart_id: str, model: str):
|
|
| 134 |
return [
|
| 135 |
"", # html_display
|
| 136 |
"", # label_info
|
| 137 |
-
[], # qa_data
|
| 138 |
-
"", # status_text
|
| 139 |
"请在左侧选择图表", # progress_text
|
| 140 |
-
|
|
|
|
| 141 |
]
|
| 142 |
|
| 143 |
# 更新状态
|
|
@@ -180,13 +181,17 @@ def load_chart_data(source: str, chart_type: str, chart_id: str, model: str):
|
|
| 180 |
stats = data_manager.get_review_stats()
|
| 181 |
status_text = f"已审核: {stats['total']} | ✅正确: {stats['correct']} | ❌错误: {stats['incorrect']} | ✏️需修改: {stats['needs_modification']}"
|
| 182 |
|
|
|
|
|
|
|
|
|
|
| 183 |
return [
|
| 184 |
html_content, # html_display
|
| 185 |
label_text, # label_info
|
| 186 |
-
qa_list, # qa_data (
|
| 187 |
status_text, # status_text
|
| 188 |
progress_text, # progress_text
|
| 189 |
-
existing_reviews # current_qa_reviews
|
|
|
|
| 190 |
]
|
| 191 |
|
| 192 |
|
|
@@ -234,6 +239,9 @@ def save_review_handler(
|
|
| 234 |
reviewer: str
|
| 235 |
) -> str:
|
| 236 |
"""保存审核记录"""
|
|
|
|
|
|
|
|
|
|
| 237 |
review_data = {
|
| 238 |
"qa_id": qa_id,
|
| 239 |
"chart_id": chart_id,
|
|
@@ -271,7 +279,7 @@ def create_ui():
|
|
| 271 |
# 自定义 CSS
|
| 272 |
custom_css = """
|
| 273 |
.chart-container {
|
| 274 |
-
height:
|
| 275 |
overflow: auto;
|
| 276 |
border: 1px solid #e0e0e0;
|
| 277 |
border-radius: 8px;
|
|
@@ -279,51 +287,12 @@ def create_ui():
|
|
| 279 |
background: #fafafa;
|
| 280 |
}
|
| 281 |
|
| 282 |
-
.qa-item {
|
| 283 |
-
border: 1px solid #e0e0e0;
|
| 284 |
-
border-radius: 8px;
|
| 285 |
-
padding: 15px;
|
| 286 |
-
margin-bottom: 15px;
|
| 287 |
-
background: white;
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
.qa-question {
|
| 291 |
-
font-weight: bold;
|
| 292 |
-
color: #1a73e8;
|
| 293 |
-
margin-bottom: 8px;
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
.qa-answer {
|
| 297 |
-
color: #0d652d;
|
| 298 |
-
padding: 8px;
|
| 299 |
-
background: #e8f5e9;
|
| 300 |
-
border-radius: 4px;
|
| 301 |
-
margin-bottom: 10px;
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
.status-correct { background-color: #d4edda !important; border-color: #c3e6cb !important; }
|
| 305 |
-
.status-incorrect { background-color: #f8d7da !important; border-color: #f5c6cb !important; }
|
| 306 |
-
.status-needs-modification { background-color: #fff3cd !important; border-color: #ffeeba !important; }
|
| 307 |
-
.status-pending { background-color: #e2e3e5 !important; border-color: #d6d8db !important; }
|
| 308 |
-
|
| 309 |
.control-panel {
|
| 310 |
background: #f8f9fa;
|
| 311 |
padding: 15px;
|
| 312 |
border-radius: 8px;
|
| 313 |
margin-bottom: 10px;
|
| 314 |
}
|
| 315 |
-
|
| 316 |
-
.stats-panel {
|
| 317 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 318 |
-
color: white;
|
| 319 |
-
padding: 15px;
|
| 320 |
-
border-radius: 8px;
|
| 321 |
-
margin-bottom: 15px;
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
.nav-button {
|
| 325 |
-
min-width: 120px;
|
| 326 |
-
}
|
| 327 |
"""
|
| 328 |
|
| 329 |
with gr.Blocks(
|
|
@@ -332,15 +301,15 @@ def create_ui():
|
|
| 332 |
css=custom_css
|
| 333 |
) as app:
|
| 334 |
|
| 335 |
-
# 隐藏的状态存储
|
| 336 |
-
|
| 337 |
-
|
| 338 |
|
| 339 |
# ==================== 标题栏 ====================
|
| 340 |
gr.Markdown("""
|
| 341 |
# 📊 图表问答数据集审核系统
|
| 342 |
|
| 343 |
-
审核每个图表对
|
| 344 |
""")
|
| 345 |
|
| 346 |
# ==================== 顶部状态栏 ====================
|
|
@@ -349,7 +318,8 @@ def create_ui():
|
|
| 349 |
label="审核统计",
|
| 350 |
value="等待加载数据...",
|
| 351 |
interactive=False,
|
| 352 |
-
show_label=False
|
|
|
|
| 353 |
)
|
| 354 |
progress_text = gr.Textbox(
|
| 355 |
label="进度",
|
|
@@ -393,8 +363,8 @@ def create_ui():
|
|
| 393 |
|
| 394 |
# 导航按钮
|
| 395 |
with gr.Row():
|
| 396 |
-
prev_btn = gr.Button("⬅️ 上一个"
|
| 397 |
-
next_btn = gr.Button("➡️ 下一个"
|
| 398 |
|
| 399 |
# 导出按钮
|
| 400 |
export_btn = gr.Button("📥 导出审核记录", variant="secondary")
|
|
@@ -429,89 +399,90 @@ def create_ui():
|
|
| 429 |
# QA 审核区
|
| 430 |
gr.Markdown("### ❓ 问答审核")
|
| 431 |
|
| 432 |
-
#
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
|
|
|
| 515 |
|
| 516 |
# ==================== 事件绑定 ====================
|
| 517 |
|
|
@@ -541,60 +512,57 @@ def create_ui():
|
|
| 541 |
)
|
| 542 |
|
| 543 |
# 选择图表 -> 加载数据
|
| 544 |
-
def on_chart_selected(source, chart_type, chart_id, model):
|
| 545 |
-
results = load_chart_data(source, chart_type, chart_id, model)
|
| 546 |
-
# 更新 QA 选择器
|
| 547 |
-
qa_list = results[2] # qa_data
|
| 548 |
-
qa_choices = [f"Q{i+1}: {qa.question[:50]}..." for i, qa in enumerate(qa_list)] if qa_list else []
|
| 549 |
-
return results + [gr.Radio(choices=qa_choices, value=qa_choices[0] if qa_choices else None)]
|
| 550 |
-
|
| 551 |
model_dropdown.change(
|
| 552 |
-
fn=
|
| 553 |
inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],
|
| 554 |
outputs=[
|
| 555 |
-
html_display, label_display,
|
| 556 |
-
|
| 557 |
]
|
| 558 |
)
|
| 559 |
|
| 560 |
chart_dropdown.change(
|
| 561 |
-
fn=
|
| 562 |
inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],
|
| 563 |
outputs=[
|
| 564 |
-
html_display, label_display,
|
| 565 |
-
|
| 566 |
]
|
| 567 |
)
|
| 568 |
|
| 569 |
# QA 选择器变化 -> 更新审核面板
|
| 570 |
-
def on_qa_selected(qa_index_str,
|
| 571 |
-
if not qa_index_str or not
|
| 572 |
-
return [""
|
| 573 |
|
| 574 |
-
# 解析索引
|
| 575 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
index = int(qa_index_str.split(":")[0].replace("Q", "")) - 1
|
| 577 |
qa = qa_list[index]
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
|
|
|
| 594 |
|
| 595 |
qa_selector.change(
|
| 596 |
fn=on_qa_selected,
|
| 597 |
-
inputs=[qa_selector,
|
| 598 |
outputs=[
|
| 599 |
current_qa_id, qa_question_display, qa_answer_display,
|
| 600 |
status_radio, issue_type_dropdown, modified_question, modified_answer, comment_textbox
|
|
@@ -644,41 +612,6 @@ def create_ui():
|
|
| 644 |
fn=lambda: gr.Textbox(visible=True),
|
| 645 |
outputs=[export_result]
|
| 646 |
)
|
| 647 |
-
|
| 648 |
-
# 键盘快捷键
|
| 649 |
-
app.load(
|
| 650 |
-
fn=lambda: None,
|
| 651 |
-
js="""
|
| 652 |
-
() => {
|
| 653 |
-
document.addEventListener('keydown', (e) => {
|
| 654 |
-
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
|
| 655 |
-
|
| 656 |
-
if (e.key === 'ArrowLeft') {
|
| 657 |
-
document.querySelector('button:has(.nav-button)')?.click();
|
| 658 |
-
// 模拟点击上一个按钮
|
| 659 |
-
const prevBtn = Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('上一个'));
|
| 660 |
-
if (prevBtn) prevBtn.click();
|
| 661 |
-
}
|
| 662 |
-
if (e.key === 'ArrowRight') {
|
| 663 |
-
const nextBtn = Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('下一个'));
|
| 664 |
-
if (nextBtn) nextBtn.click();
|
| 665 |
-
}
|
| 666 |
-
if (e.key === '1') {
|
| 667 |
-
document.querySelector('input[value="correct"]')?.click();
|
| 668 |
-
}
|
| 669 |
-
if (e.key === '2') {
|
| 670 |
-
document.querySelector('input[value="incorrect"]')?.click();
|
| 671 |
-
}
|
| 672 |
-
if (e.key === '3') {
|
| 673 |
-
document.querySelector('input[value="needs_modification"]')?.click();
|
| 674 |
-
}
|
| 675 |
-
if (e.key === '4') {
|
| 676 |
-
document.querySelector('input[value="pending"]')?.click();
|
| 677 |
-
}
|
| 678 |
-
});
|
| 679 |
-
}
|
| 680 |
-
"""
|
| 681 |
-
)
|
| 682 |
|
| 683 |
return app
|
| 684 |
|
|
|
|
| 1 |
"""
|
| 2 |
+
图表问答数据集审核系统 - Gradio 5.x 应用
|
| 3 |
用于人工审核每个图表对应的问题和答案是否合理正确
|
| 4 |
"""
|
| 5 |
import gradio as gr
|
|
|
|
| 97 |
return sources, chart_types, charts, models
|
| 98 |
|
| 99 |
|
| 100 |
+
def update_chart_type_dropdown(source: str):
|
| 101 |
"""更新图表类型下拉框"""
|
| 102 |
state.current_source = source
|
| 103 |
structure = data_manager.get_dataset_structure()
|
|
|
|
| 107 |
return gr.Dropdown(choices=chart_types, value=chart_types[0] if chart_types else None)
|
| 108 |
|
| 109 |
|
| 110 |
+
def update_chart_dropdown(source: str, chart_type: str):
|
| 111 |
"""更新图表和模型下拉框"""
|
| 112 |
state.current_source = source
|
| 113 |
state.current_chart_type = chart_type
|
|
|
|
| 134 |
return [
|
| 135 |
"", # html_display
|
| 136 |
"", # label_info
|
| 137 |
+
"[]", # qa_data (JSON string)
|
| 138 |
+
"等待加载数据...", # status_text
|
| 139 |
"请在左侧选择图表", # progress_text
|
| 140 |
+
"{}", # current_qa_reviews (JSON string)
|
| 141 |
+
gr.Radio(choices=[], value=None) # qa_selector
|
| 142 |
]
|
| 143 |
|
| 144 |
# 更新状态
|
|
|
|
| 181 |
stats = data_manager.get_review_stats()
|
| 182 |
status_text = f"已审核: {stats['total']} | ✅正确: {stats['correct']} | ❌错误: {stats['incorrect']} | ✏️需修改: {stats['needs_modification']}"
|
| 183 |
|
| 184 |
+
# QA 选择器选项
|
| 185 |
+
qa_choices = [f"Q{i+1}: {qa.question[:50]}..." for i, qa in enumerate(qa_list)] if qa_list else []
|
| 186 |
+
|
| 187 |
return [
|
| 188 |
html_content, # html_display
|
| 189 |
label_text, # label_info
|
| 190 |
+
json.dumps([{"id": qa.id, "question": qa.question, "answer": qa.answer} for qa in qa_list]), # qa_data (JSON string)
|
| 191 |
status_text, # status_text
|
| 192 |
progress_text, # progress_text
|
| 193 |
+
json.dumps(existing_reviews), # current_qa_reviews (JSON string)
|
| 194 |
+
gr.Radio(choices=qa_choices, value=qa_choices[0] if qa_choices else None) # qa_selector
|
| 195 |
]
|
| 196 |
|
| 197 |
|
|
|
|
| 239 |
reviewer: str
|
| 240 |
) -> str:
|
| 241 |
"""保存审核记录"""
|
| 242 |
+
if not qa_id:
|
| 243 |
+
return "❌ 请先选择一个问答对"
|
| 244 |
+
|
| 245 |
review_data = {
|
| 246 |
"qa_id": qa_id,
|
| 247 |
"chart_id": chart_id,
|
|
|
|
| 279 |
# 自定义 CSS
|
| 280 |
custom_css = """
|
| 281 |
.chart-container {
|
| 282 |
+
height: 500px;
|
| 283 |
overflow: auto;
|
| 284 |
border: 1px solid #e0e0e0;
|
| 285 |
border-radius: 8px;
|
|
|
|
| 287 |
background: #fafafa;
|
| 288 |
}
|
| 289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
.control-panel {
|
| 291 |
background: #f8f9fa;
|
| 292 |
padding: 15px;
|
| 293 |
border-radius: 8px;
|
| 294 |
margin-bottom: 10px;
|
| 295 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
"""
|
| 297 |
|
| 298 |
with gr.Blocks(
|
|
|
|
| 301 |
css=custom_css
|
| 302 |
) as app:
|
| 303 |
|
| 304 |
+
# 隐藏的状态存储(使用 JSON 字符串)
|
| 305 |
+
qa_data_json = gr.State(value="[]")
|
| 306 |
+
current_reviews_json = gr.State(value="{}")
|
| 307 |
|
| 308 |
# ==================== 标题栏 ====================
|
| 309 |
gr.Markdown("""
|
| 310 |
# 📊 图表问答数据集审核系统
|
| 311 |
|
| 312 |
+
审核每个图表对应的问题和答案是否合理正确。使用 ← → 按钮切换图表。
|
| 313 |
""")
|
| 314 |
|
| 315 |
# ==================== 顶部状态栏 ====================
|
|
|
|
| 318 |
label="审核统计",
|
| 319 |
value="等待加载数据...",
|
| 320 |
interactive=False,
|
| 321 |
+
show_label=False,
|
| 322 |
+
scale=2
|
| 323 |
)
|
| 324 |
progress_text = gr.Textbox(
|
| 325 |
label="进度",
|
|
|
|
| 363 |
|
| 364 |
# 导航按钮
|
| 365 |
with gr.Row():
|
| 366 |
+
prev_btn = gr.Button("⬅️ 上一个")
|
| 367 |
+
next_btn = gr.Button("➡️ 下一个")
|
| 368 |
|
| 369 |
# 导出按钮
|
| 370 |
export_btn = gr.Button("📥 导出审核记录", variant="secondary")
|
|
|
|
| 399 |
# QA 审核区
|
| 400 |
gr.Markdown("### ❓ 问答审核")
|
| 401 |
|
| 402 |
+
# 当前选中的 QA 信息(隐藏)
|
| 403 |
+
current_qa_id = gr.Textbox(visible=False, value="")
|
| 404 |
+
|
| 405 |
+
# QA 显示
|
| 406 |
+
qa_question_display = gr.Textbox(
|
| 407 |
+
label="问题",
|
| 408 |
+
interactive=False,
|
| 409 |
+
lines=2,
|
| 410 |
+
value=""
|
| 411 |
+
)
|
| 412 |
+
qa_answer_display = gr.Textbox(
|
| 413 |
+
label="答案",
|
| 414 |
+
interactive=False,
|
| 415 |
+
lines=1,
|
| 416 |
+
value=""
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
+
# QA 选择器
|
| 420 |
+
qa_selector = gr.Radio(
|
| 421 |
+
label="选择要审核的问答对",
|
| 422 |
+
choices=[],
|
| 423 |
+
interactive=True
|
| 424 |
+
)
|
| 425 |
+
|
| 426 |
+
gr.Markdown("---")
|
| 427 |
+
gr.Markdown("#### 审核操作")
|
| 428 |
+
|
| 429 |
+
# 审核状态选择
|
| 430 |
+
status_radio = gr.Radio(
|
| 431 |
+
label="审核状态",
|
| 432 |
+
choices=[
|
| 433 |
+
("✅ 正确", "correct"),
|
| 434 |
+
("❌ 错误", "incorrect"),
|
| 435 |
+
("✏️ 需修改", "needs_modification"),
|
| 436 |
+
("⏳ 待定", "pending")
|
| 437 |
+
],
|
| 438 |
+
value="pending",
|
| 439 |
+
interactive=True
|
| 440 |
+
)
|
| 441 |
+
|
| 442 |
+
# 问题类型
|
| 443 |
+
issue_type_dropdown = gr.Dropdown(
|
| 444 |
+
label="问题类型",
|
| 445 |
+
choices=[
|
| 446 |
+
"问题歧义",
|
| 447 |
+
"答案错误",
|
| 448 |
+
"图表不清晰",
|
| 449 |
+
"问题不合理",
|
| 450 |
+
"答案格式错误",
|
| 451 |
+
"其他"
|
| 452 |
+
],
|
| 453 |
+
interactive=True,
|
| 454 |
+
value=""
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
# 修改后的问题和答案
|
| 458 |
+
modified_question = gr.Textbox(
|
| 459 |
+
label="修改后的问题",
|
| 460 |
+
placeholder="如需修改问题,请在此输入...",
|
| 461 |
+
lines=2,
|
| 462 |
+
interactive=True,
|
| 463 |
+
value=""
|
| 464 |
+
)
|
| 465 |
+
|
| 466 |
+
modified_answer = gr.Textbox(
|
| 467 |
+
label="修改后的答案",
|
| 468 |
+
placeholder="如需修改答案,请在此输入...",
|
| 469 |
+
lines=1,
|
| 470 |
+
interactive=True,
|
| 471 |
+
value=""
|
| 472 |
+
)
|
| 473 |
+
|
| 474 |
+
# 评论
|
| 475 |
+
comment_textbox = gr.Textbox(
|
| 476 |
+
label="评论/备注",
|
| 477 |
+
placeholder="请输入审核意见或备注...",
|
| 478 |
+
lines=2,
|
| 479 |
+
interactive=True,
|
| 480 |
+
value=""
|
| 481 |
+
)
|
| 482 |
+
|
| 483 |
+
# 保存按钮
|
| 484 |
+
save_btn = gr.Button("💾 保存审核结果", variant="primary")
|
| 485 |
+
save_result = gr.Textbox(label="", visible=False)
|
| 486 |
|
| 487 |
# ==================== 事件绑定 ====================
|
| 488 |
|
|
|
|
| 512 |
)
|
| 513 |
|
| 514 |
# 选择图表 -> 加载数据
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
model_dropdown.change(
|
| 516 |
+
fn=load_chart_data,
|
| 517 |
inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],
|
| 518 |
outputs=[
|
| 519 |
+
html_display, label_display, qa_data_json, status_text, progress_text,
|
| 520 |
+
current_reviews_json, qa_selector
|
| 521 |
]
|
| 522 |
)
|
| 523 |
|
| 524 |
chart_dropdown.change(
|
| 525 |
+
fn=load_chart_data,
|
| 526 |
inputs=[source_dropdown, chart_type_dropdown, chart_dropdown, model_dropdown],
|
| 527 |
outputs=[
|
| 528 |
+
html_display, label_display, qa_data_json, status_text, progress_text,
|
| 529 |
+
current_reviews_json, qa_selector
|
| 530 |
]
|
| 531 |
)
|
| 532 |
|
| 533 |
# QA 选择器变化 -> 更新审核面板
|
| 534 |
+
def on_qa_selected(qa_index_str, qa_json, reviews_json):
|
| 535 |
+
if not qa_index_str or not qa_json:
|
| 536 |
+
return ["", "", "", gr.Radio(value="pending"), "", "", "", ""]
|
| 537 |
|
|
|
|
| 538 |
try:
|
| 539 |
+
qa_list = json.loads(qa_json)
|
| 540 |
+
reviews = json.loads(reviews_json)
|
| 541 |
+
|
| 542 |
+
# 解析索引
|
| 543 |
index = int(qa_index_str.split(":")[0].replace("Q", "")) - 1
|
| 544 |
qa = qa_list[index]
|
| 545 |
+
|
| 546 |
+
# 检查是否有现有审核
|
| 547 |
+
review = reviews.get(qa['id'], {})
|
| 548 |
+
|
| 549 |
+
return [
|
| 550 |
+
qa['id'], # current_qa_id
|
| 551 |
+
qa['question'], # qa_question_display
|
| 552 |
+
qa['answer'], # qa_answer_display
|
| 553 |
+
gr.Radio(value=review.get('status', 'pending')), # status_radio
|
| 554 |
+
review.get('issue_type', ''), # issue_type_dropdown
|
| 555 |
+
review.get('modified_question', ''), # modified_question
|
| 556 |
+
review.get('modified_answer', ''), # modified_answer
|
| 557 |
+
review.get('comment', '') # comment_textbox
|
| 558 |
+
]
|
| 559 |
+
except Exception as e:
|
| 560 |
+
print(f"Error in on_qa_selected: {e}")
|
| 561 |
+
return ["", "", "", gr.Radio(value="pending"), "", "", "", ""]
|
| 562 |
|
| 563 |
qa_selector.change(
|
| 564 |
fn=on_qa_selected,
|
| 565 |
+
inputs=[qa_selector, qa_data_json, current_reviews_json],
|
| 566 |
outputs=[
|
| 567 |
current_qa_id, qa_question_display, qa_answer_display,
|
| 568 |
status_radio, issue_type_dropdown, modified_question, modified_answer, comment_textbox
|
|
|
|
| 612 |
fn=lambda: gr.Textbox(visible=True),
|
| 613 |
outputs=[export_result]
|
| 614 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
|
| 616 |
return app
|
| 617 |
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
# Gradio 审核系统依赖
|
| 2 |
|
| 3 |
-
gradio>=
|
| 4 |
python-multipart>=0.0.6
|
|
|
|
| 1 |
# Gradio 审核系统依赖
|
| 2 |
|
| 3 |
+
gradio>=5.0.0
|
| 4 |
python-multipart>=0.0.6
|