Spaces:
Sleeping
Sleeping
Feng Chike commited on
Commit ·
ed14043
1
Parent(s): 661ecec
fix: 升级 gradio 5.29.0,修复 schema bool bug + Chatbot type=messages
Browse files- README.md +1 -1
- main.py +102 -44
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🧠
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: "5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: "5.29.0"
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
main.py
CHANGED
|
@@ -6,20 +6,73 @@ from counselor import PsychodynamicCounselor
|
|
| 6 |
counselor = None
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def build_status_panel(c):
|
| 10 |
"""构建会话状态 Markdown 富文本面板"""
|
| 11 |
score = c._last_disclosure_score
|
| 12 |
turn = c.turn_number
|
| 13 |
-
|
| 14 |
-
# 揭露深度进度条
|
| 15 |
-
filled = "█" * score + "░" * (10 - score)
|
| 16 |
-
# 揭露趋势
|
| 17 |
history = c._disclosure_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if len(history) >= 2:
|
| 19 |
diff = history[-1] - history[-2]
|
| 20 |
-
trend = "
|
|
|
|
| 21 |
else:
|
| 22 |
trend = "·"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# 维度指示灯
|
| 25 |
dims = c._last_dimensions
|
|
@@ -27,53 +80,55 @@ def build_status_panel(c):
|
|
| 27 |
"A": "具体事件", "B": "情绪表达", "C": "具体情绪",
|
| 28 |
"D": "自我反思", "E": "回避触及",
|
| 29 |
}
|
|
|
|
| 30 |
dim_parts = []
|
| 31 |
for k in ["A", "B", "C", "D", "E"]:
|
| 32 |
on = dims.get(k, False)
|
| 33 |
icon = "🟢" if on else "⚫"
|
| 34 |
-
dim_parts.append(f"{icon} {
|
| 35 |
-
dim_line = "
|
| 36 |
-
|
| 37 |
-
# 历史火花线 (sparkline)
|
| 38 |
-
spark_chars = " ▁▂▃▄▅▆▇█"
|
| 39 |
-
spark = ""
|
| 40 |
-
for s in history[-20:]:
|
| 41 |
-
idx = min(s, 9)
|
| 42 |
-
spark += spark_chars[idx]
|
| 43 |
-
if not spark:
|
| 44 |
-
spark = "—"
|
| 45 |
|
|
|
|
| 46 |
lines = []
|
| 47 |
-
lines.append("###
|
| 48 |
lines.append("")
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
lines.append(
|
| 52 |
-
lines.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
lines.append(f"| **深度轨迹** | `{spark}` |")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
lines.append("")
|
| 55 |
-
lines.append(f"**维度分析** {dim_line}")
|
| 56 |
|
| 57 |
-
# 督导
|
|
|
|
| 58 |
if c.current_guidance:
|
| 59 |
g = c.current_guidance
|
| 60 |
direction = g.get("direction", "—")
|
| 61 |
principles = g.get("principles", [])
|
| 62 |
evidence = g.get("evidence", "")
|
| 63 |
|
| 64 |
-
lines.append("")
|
| 65 |
-
lines.append("---")
|
| 66 |
lines.append("#### ▸ 督导指令")
|
| 67 |
-
lines.append(
|
|
|
|
| 68 |
if principles:
|
| 69 |
lines.append(">")
|
| 70 |
-
for p in principles[:3]:
|
| 71 |
-
lines.append(f">
|
| 72 |
if evidence:
|
| 73 |
-
lines.append(
|
| 74 |
-
lines.append(f">
|
|
|
|
| 75 |
|
| 76 |
-
# 推理引擎
|
| 77 |
ts = c._last_trace_stats
|
| 78 |
if ts:
|
| 79 |
timing = ts.get("timing", {})
|
|
@@ -84,23 +139,26 @@ def build_status_panel(c):
|
|
| 84 |
selected = ts.get("selected", "")
|
| 85 |
best_score = ts.get("best_score", 0)
|
| 86 |
best_delta = ts.get("best_delta", 0)
|
|
|
|
| 87 |
|
| 88 |
-
lines.append("")
|
| 89 |
lines.append("#### ▸ PUCT 推理引擎")
|
| 90 |
-
lines.append(
|
| 91 |
-
lines.append(
|
| 92 |
-
lines.append(
|
| 93 |
-
lines.append(f"| **
|
| 94 |
-
lines.append(f"| **
|
| 95 |
-
lines.append(f"| **
|
| 96 |
-
lines.append(f"| **
|
|
|
|
|
|
|
|
|
|
| 97 |
else:
|
|
|
|
| 98 |
lines.append("")
|
| 99 |
-
lines.append("
|
| 100 |
-
lines.append("#### ▸ 督导引擎")
|
| 101 |
-
lines.append(f"> ⏳ 每轮同步推理中…")
|
| 102 |
|
| 103 |
-
# 评估理由
|
| 104 |
if c._last_reasoning:
|
| 105 |
lines.append("")
|
| 106 |
lines.append(f"<details><summary>📋 评估理由</summary>\n\n{c._last_reasoning}\n\n</details>")
|
|
@@ -200,7 +258,7 @@ with gr.Blocks(title="Freud-Zero MVP") as app:
|
|
| 200 |
btn_start = gr.Button("开始新会话", variant="primary")
|
| 201 |
btn_end = gr.Button("结束会话", variant="stop")
|
| 202 |
|
| 203 |
-
chatbot = gr.Chatbot(label="对话", height=480)
|
| 204 |
|
| 205 |
with gr.Row():
|
| 206 |
user_input = gr.Textbox(placeholder="说你想说的……", show_label=False, scale=4)
|
|
|
|
| 6 |
counselor = None
|
| 7 |
|
| 8 |
|
| 9 |
+
def _depth_level(score):
|
| 10 |
+
"""将 1-10 分映射为探索层级"""
|
| 11 |
+
if score <= 2:
|
| 12 |
+
return "L1 · 表层", "社交性叙述,回避情感"
|
| 13 |
+
elif score <= 4:
|
| 14 |
+
return "L2 · 事件", "具体事件浮现,情绪初现"
|
| 15 |
+
elif score <= 6:
|
| 16 |
+
return "L3 · 情感", "情绪深化,开始反思模式"
|
| 17 |
+
elif score <= 8:
|
| 18 |
+
return "L4 · 核心", "触及核心冲突与早期经历"
|
| 19 |
+
else:
|
| 20 |
+
return "L5 · 突破", "深层揭露,防御松动"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _phase_label(turn):
|
| 24 |
+
"""会话阶段"""
|
| 25 |
+
if turn <= 3:
|
| 26 |
+
return "建立联盟"
|
| 27 |
+
elif turn <= 8:
|
| 28 |
+
return "探索展开"
|
| 29 |
+
elif turn <= 15:
|
| 30 |
+
return "深层工作"
|
| 31 |
+
else:
|
| 32 |
+
return "整合修通"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
def build_status_panel(c):
|
| 36 |
"""构建会话状态 Markdown 富文本面板"""
|
| 37 |
score = c._last_disclosure_score
|
| 38 |
turn = c.turn_number
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
history = c._disclosure_history
|
| 40 |
+
|
| 41 |
+
# ── 探索层级 ──
|
| 42 |
+
level_name, level_desc = _depth_level(score)
|
| 43 |
+
phase = _phase_label(turn)
|
| 44 |
+
|
| 45 |
+
# 揭露深度进度条(渐变风格)
|
| 46 |
+
bar_chars = "░▒▓█"
|
| 47 |
+
filled_bar = ""
|
| 48 |
+
for i in range(10):
|
| 49 |
+
if i < score:
|
| 50 |
+
ci = min(i // 3, 3)
|
| 51 |
+
filled_bar += bar_chars[ci]
|
| 52 |
+
else:
|
| 53 |
+
filled_bar += "·"
|
| 54 |
+
|
| 55 |
+
# 趋势计算
|
| 56 |
if len(history) >= 2:
|
| 57 |
diff = history[-1] - history[-2]
|
| 58 |
+
trend = "▲" if diff > 0 else ("▼" if diff < 0 else "━")
|
| 59 |
+
trend_word = f"+{diff}" if diff > 0 else str(diff) if diff < 0 else "±0"
|
| 60 |
else:
|
| 61 |
trend = "·"
|
| 62 |
+
trend_word = "—"
|
| 63 |
+
|
| 64 |
+
# 均值 & 峰值
|
| 65 |
+
avg_score = sum(history) / len(history) if history else 0
|
| 66 |
+
peak_score = max(history) if history else 0
|
| 67 |
+
|
| 68 |
+
# 历史火花线 (sparkline)
|
| 69 |
+
spark_chars = " ▁▂▃▄▅▆▇█"
|
| 70 |
+
spark = ""
|
| 71 |
+
for s in history[-20:]:
|
| 72 |
+
idx = min(s, 9)
|
| 73 |
+
spark += spark_chars[idx]
|
| 74 |
+
if not spark:
|
| 75 |
+
spark = "—"
|
| 76 |
|
| 77 |
# 维度指示灯
|
| 78 |
dims = c._last_dimensions
|
|
|
|
| 80 |
"A": "具体事件", "B": "情绪表达", "C": "具体情绪",
|
| 81 |
"D": "自我反思", "E": "回避触及",
|
| 82 |
}
|
| 83 |
+
dim_on = sum(1 for k in ["A", "B", "C", "D", "E"] if dims.get(k, False))
|
| 84 |
dim_parts = []
|
| 85 |
for k in ["A", "B", "C", "D", "E"]:
|
| 86 |
on = dims.get(k, False)
|
| 87 |
icon = "🟢" if on else "⚫"
|
| 88 |
+
dim_parts.append(f"{icon} {dim_labels[k]}")
|
| 89 |
+
dim_line = " · ".join(dim_parts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
# ── 构建面板 ──
|
| 92 |
lines = []
|
| 93 |
+
lines.append("### ◈ SESSION MONITOR")
|
| 94 |
lines.append("")
|
| 95 |
+
|
| 96 |
+
# 核心指标表
|
| 97 |
+
lines.append("| | |")
|
| 98 |
+
lines.append("|:---|:---|")
|
| 99 |
+
lines.append(f"| **轮次** | `T{turn}` · {phase} |")
|
| 100 |
+
lines.append(f"| **探索层级** | **{level_name}** — {level_desc} |")
|
| 101 |
+
lines.append(f"| **揭露深度** | `{filled_bar}` **{score}/10** {trend} ({trend_word}) |")
|
| 102 |
+
lines.append(f"| **均值 / 峰值** | avg `{avg_score:.1f}` · peak `{peak_score}` |")
|
| 103 |
lines.append(f"| **深度轨迹** | `{spark}` |")
|
| 104 |
+
lines.append(f"| **维度命中** | **{dim_on}/5** |")
|
| 105 |
+
lines.append("")
|
| 106 |
+
|
| 107 |
+
# 维度详情
|
| 108 |
+
lines.append(f"> {dim_line}")
|
| 109 |
lines.append("")
|
|
|
|
| 110 |
|
| 111 |
+
# ── 督导模块 ──
|
| 112 |
+
lines.append("---")
|
| 113 |
if c.current_guidance:
|
| 114 |
g = c.current_guidance
|
| 115 |
direction = g.get("direction", "—")
|
| 116 |
principles = g.get("principles", [])
|
| 117 |
evidence = g.get("evidence", "")
|
| 118 |
|
|
|
|
|
|
|
| 119 |
lines.append("#### ▸ 督导指令")
|
| 120 |
+
lines.append("")
|
| 121 |
+
lines.append(f"> 🎯 **{direction}**")
|
| 122 |
if principles:
|
| 123 |
lines.append(">")
|
| 124 |
+
for i, p in enumerate(principles[:3], 1):
|
| 125 |
+
lines.append(f"> {i}. {p}")
|
| 126 |
if evidence:
|
| 127 |
+
lines.append(">")
|
| 128 |
+
lines.append(f"> 📌 {evidence[:100]}{'…' if len(evidence) > 100 else ''}")
|
| 129 |
+
lines.append("")
|
| 130 |
|
| 131 |
+
# ── PUCT 推理引擎 ──
|
| 132 |
ts = c._last_trace_stats
|
| 133 |
if ts:
|
| 134 |
timing = ts.get("timing", {})
|
|
|
|
| 139 |
selected = ts.get("selected", "")
|
| 140 |
best_score = ts.get("best_score", 0)
|
| 141 |
best_delta = ts.get("best_delta", 0)
|
| 142 |
+
predicted = ts.get("predicted_disclosure", "?")
|
| 143 |
|
| 144 |
+
lines.append("---")
|
| 145 |
lines.append("#### ▸ PUCT 推理引擎")
|
| 146 |
+
lines.append("")
|
| 147 |
+
lines.append("| | |")
|
| 148 |
+
lines.append("|:---|:---|")
|
| 149 |
+
lines.append(f"| **搜索架构** | `L1 → L2 → L3 → L4 → L5 → L6` (6层深度) |")
|
| 150 |
+
lines.append(f"| **种子方向** | {' / '.join(seeds) if seeds else '—'} |")
|
| 151 |
+
lines.append(f"| **路径探索** | {total_paths} 候选 → {deep} 深探 |")
|
| 152 |
+
lines.append(f"| **最优路径** | `{selected}` |")
|
| 153 |
+
lines.append(f"| **路径评分** | score=**{best_score}** · Δ=**{best_delta:+.1f}** |")
|
| 154 |
+
lines.append(f"| **预测揭露** | **{predicted}**/10 |")
|
| 155 |
+
lines.append(f"| **推理耗时** | `{total_s:.1f}s` |")
|
| 156 |
else:
|
| 157 |
+
lines.append("#### ▸ 推理引擎")
|
| 158 |
lines.append("")
|
| 159 |
+
lines.append("> ⏳ 同步推理中…")
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
# ── 评估理由(折叠) ──
|
| 162 |
if c._last_reasoning:
|
| 163 |
lines.append("")
|
| 164 |
lines.append(f"<details><summary>📋 评估理由</summary>\n\n{c._last_reasoning}\n\n</details>")
|
|
|
|
| 258 |
btn_start = gr.Button("开始新会话", variant="primary")
|
| 259 |
btn_end = gr.Button("结束会话", variant="stop")
|
| 260 |
|
| 261 |
+
chatbot = gr.Chatbot(label="对话", height=480, type="messages")
|
| 262 |
|
| 263 |
with gr.Row():
|
| 264 |
user_input = gr.Textbox(placeholder="说你想说的……", show_label=False, scale=4)
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
gradio==5.
|
| 2 |
langchain>=0.3
|
| 3 |
langchain-core>=0.3
|
| 4 |
langchain-openai>=0.3
|
|
|
|
| 1 |
+
gradio==5.29.0
|
| 2 |
langchain>=0.3
|
| 3 |
langchain-core>=0.3
|
| 4 |
langchain-openai>=0.3
|