-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
303 lines (261 loc) · 10.9 KB
/
Copy pathapp.py
File metadata and controls
303 lines (261 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
"""Streamlit dashboard for DataToInsightWorkflowAgent."""
from __future__ import annotations
import json
from pathlib import Path
import streamlit as st
from data_to_insight.ui_helpers import (
CLASSIFICATION_OPTIONS,
PRIORITY_OPTIONS,
ROUTE_OPTIONS,
build_processed_table,
build_summary_metrics,
export_panel_status,
filter_items,
flatten_actions,
get_default_paths,
get_high_value_items,
get_noise_review_items,
group_actions_by_priority,
load_or_run_dashboard_data,
)
st.set_page_config(
page_title="DataToInsightWorkflowAgent",
layout="wide",
)
def apply_styles() -> None:
st.markdown(
"""
<style>
.block-container { padding-top: 1.6rem; padding-bottom: 3rem; }
.d2i-hero {
border: 1px solid #e7edf3;
border-radius: 8px;
padding: 1.25rem 1.35rem;
background: #fbfcfe;
margin-bottom: 1rem;
}
.d2i-hero h1 { margin: 0 0 .35rem 0; font-size: 2rem; }
.d2i-hero p { margin: .2rem 0; color: #485466; }
.d2i-badges span {
display: inline-block;
border: 1px solid #d9e2ec;
border-radius: 999px;
padding: .22rem .55rem;
margin: .35rem .35rem 0 0;
background: #ffffff;
color: #223044;
font-size: .82rem;
}
.d2i-card {
border: 1px solid #e5eaf0;
border-radius: 8px;
padding: 1rem;
background: #ffffff;
margin: .6rem 0;
}
.d2i-card h3 { margin-top: 0; font-size: 1.05rem; }
.d2i-muted { color: #607086; font-size: .92rem; }
.d2i-notice {
border-left: 4px solid #4f7cff;
padding: .8rem 1rem;
background: #f6f8fc;
border-radius: 6px;
}
</style>
""",
unsafe_allow_html=True,
)
def render_hero() -> None:
st.markdown(
"""
<div class="d2i-hero">
<h1>数据洞察工作流智能体</h1>
<p><strong>DataToInsightWorkflowAgent</strong></p>
<p>把杂乱资料转化成高价值信号、优先级判断和下一步行动建议。</p>
<p>A local-first, public-safe data-to-insight workflow agent for ranked insight signals, action recommendations, and AgentHub-ready exports.</p>
<div class="d2i-badges">
<span>Local-first</span>
<span>Public-safe</span>
<span>Demo-mode</span>
<span>AgentHub-ready</span>
<span>No real connector</span>
<span>Synthetic demo data only</span>
</div>
</div>
""",
unsafe_allow_html=True,
)
def render_workflow_map() -> None:
steps = [
("Data Intake", "读取 synthetic demo data,不上传真实文件。"),
("Normalization", "统一字段、文本和标签,方便后续处理。"),
("Classification", "规则型分类,识别学习、商业、项目、求职和噪音。"),
("Scoring", "多维 0-5 评分,生成优先级。"),
("Noise Filtering", "分离低价值、重复和需复核内容。"),
("Insight Extraction", "提取可用信号,不做普通全文总结。"),
("Action Recommendation", "生成下一步行动和目标 Agent。"),
("Export / AgentHub", "导出 Markdown report 和 AgentHub JSON。"),
]
st.subheader("Workflow Map / 工作流地图")
columns = st.columns(4)
for index, (title, description) in enumerate(steps):
with columns[index % 4]:
st.markdown(
f"""
<div class="d2i-card">
<h3>{index + 1}. {title}</h3>
<p class="d2i-muted">{description}</p>
</div>
""",
unsafe_allow_html=True,
)
def first_signal(item: dict) -> dict:
signals = item.get("key_signals", [])
return signals[0] if signals else {}
def first_action(item: dict) -> dict:
actions = item.get("recommended_actions", [])
return actions[0] if actions else {}
def render_high_value_items(items: list[dict]) -> None:
st.subheader("High-value Signals / 高价值信号")
high_items = get_high_value_items(items)
if not high_items:
st.info("No high-value item matches the current filters.")
return
for item in high_items:
signal = first_signal(item)
action = first_action(item)
st.markdown(
f"""
<div class="d2i-card">
<h3>{item.get("title")}</h3>
<p><strong>Classification:</strong> {item.get("classification")} <strong>Score:</strong> {item.get("overall_score")} <strong>Route:</strong> {item.get("recommended_route")}</p>
<p><strong>Key signal:</strong> {signal.get("signal", "")}</p>
<p><strong>Why it matters:</strong> {signal.get("why_it_matters", "")}</p>
<p><strong>Possible use:</strong> {signal.get("possible_use", "")}</p>
<p><strong>Recommended action:</strong> {action.get("action_type", "")} -> {action.get("target", "")}</p>
</div>
""",
unsafe_allow_html=True,
)
def render_action_board(items: list[dict]) -> None:
st.subheader("Action Board / 行动建议板")
grouped = group_actions_by_priority(flatten_actions(items))
for group_name, actions in grouped.items():
with st.expander(f"{group_name} ({len(actions)})", expanded=group_name == "High Priority Actions"):
if not actions:
st.caption("No actions in this group.")
continue
for action in actions:
st.markdown(
f"""
<div class="d2i-card">
<h3>{action.get("action_type")} -> {action.get("target")}</h3>
<p><strong>Source:</strong> {action.get("source_title")}</p>
<p><strong>Priority:</strong> {action.get("priority")} <strong>Classification:</strong> {action.get("classification")}</p>
<p><strong>Reason:</strong> {action.get("reason")}</p>
<p><strong>Next step:</strong> {action.get("next_step")}</p>
</div>
""",
unsafe_allow_html=True,
)
def render_noise_queue(items: list[dict]) -> None:
st.subheader("Noise / Review Queue / 噪音与复核队列")
queue_items = get_noise_review_items(items)
if not queue_items:
st.info("No low-value, noise, or review item matches the current filters.")
return
for item in queue_items:
st.markdown(
f"""
<div class="d2i-card">
<h3>{item.get("title")}</h3>
<p><strong>Classification:</strong> {item.get("classification")} <strong>Score:</strong> {item.get("overall_score")}</p>
<p><strong>Keep or ignore:</strong> {item.get("keep_or_ignore")}</p>
<p><strong>Reason:</strong> {item.get("reason")}</p>
<p><strong>Why not high priority:</strong> lower score, weak evidence, duplicate/noise label, or review-needed status.</p>
</div>
""",
unsafe_allow_html=True,
)
def render_export_panel(summary: dict, root: Path) -> None:
st.subheader("Export / AgentHub Panel")
status = export_panel_status(root)
left, right = st.columns(2)
with left:
st.markdown("**Markdown report**")
st.code(str(status["markdown_report_path"]))
st.write("Exists:", status["markdown_report_exists"])
st.markdown("**AgentHub summary JSON**")
st.code(str(status["agenthub_summary_path"]))
st.write("Exists:", status["agenthub_summary_exists"])
with right:
st.markdown("**Agent manifest**")
st.code(str(status["agent_manifest_path"]))
st.write("Exists:", status["agent_manifest_exists"])
st.markdown("**Agent contract**")
st.code(str(status["agent_contract_path"]))
st.write("Exists:", status["agent_contract_exists"])
st.markdown("**AgentHub-ready summary**")
agenthub_keys = [
"agent_id",
"agent_name",
"status",
"demo_mode",
"public_safe",
"total_items_processed",
"high_value_signals",
"recommended_actions_count",
"top_routes",
]
st.json({key: summary.get(key) for key in agenthub_keys})
def render_public_safe_notice() -> None:
st.markdown(
"""
<div class="d2i-notice">
<strong>Public-safe Notice</strong><br>
This dashboard uses synthetic demo data only. No real connector is enabled. No external API call is made.
No .env, token, credential, or secret is required. No real user file is processed.<br><br>
本 Dashboard 仅使用 synthetic demo data。未接入真实 connector。不调用外部 API。
不读取 .env、token、credential 或 secret。不处理真实用户文件。
</div>
""",
unsafe_allow_html=True,
)
def main() -> None:
apply_styles()
root = Path(__file__).resolve().parent
paths = get_default_paths(root)
st.sidebar.header("Controls / 控制面板")
run_demo = st.sidebar.button("Run demo pipeline")
priority_filter = st.sidebar.selectbox("Priority filter", PRIORITY_OPTIONS)
classification_filter = st.sidebar.selectbox("Classification filter", CLASSIFICATION_OPTIONS)
route_filter = st.sidebar.selectbox("Route filter", ROUTE_OPTIONS)
st.sidebar.divider()
st.sidebar.caption("Default input: demo_data/demo_items.json")
st.sidebar.caption("No upload. No connector. Synthetic demo data only.")
items, summary = load_or_run_dashboard_data(
paths["input_path"],
paths["output_dir"],
force_run=run_demo,
)
filtered_items = filter_items(items, priority_filter, classification_filter, route_filter)
metrics = build_summary_metrics(summary)
render_hero()
st.subheader("Overview Metrics / 总览指标")
metric_cols = st.columns(6)
metric_cols[0].metric("Total Items Processed", metrics["total_items_processed"])
metric_cols[1].metric("High-value Signals", metrics["high_value_signals"])
metric_cols[2].metric("Medium-value Items", metrics["medium_value_items"])
metric_cols[3].metric("Low / Noise / Review", metrics["low_value_or_noise_items"])
metric_cols[4].metric("Recommended Actions", metrics["recommended_actions_count"])
metric_cols[5].metric("Top Route", metrics["top_recommended_route"])
render_workflow_map()
render_high_value_items(filtered_items)
render_action_board(filtered_items)
render_noise_queue(filtered_items)
st.subheader("Processed Items Table / 处理结果表")
st.dataframe(build_processed_table(filtered_items), use_container_width=True, hide_index=True)
render_export_panel(summary, root)
render_public_safe_notice()
if __name__ == "__main__":
main()