Spaces:
Running
Running
chenge
commited on
Commit
·
9d82030
1
Parent(s):
20c5c0f
增加可视化
Browse files
app.py
CHANGED
@@ -956,8 +956,9 @@ css = """
|
|
956 |
.thinking-content .ant-collapse {
|
957 |
background: linear-gradient(135deg, #f6f9fc 0%, #f0f4f8 100%);
|
958 |
border: 1px solid #e1e8ed;
|
959 |
-
border-radius: 8px;
|
960 |
-
|
|
|
961 |
}
|
962 |
.thinking-content .ant-collapse > .ant-collapse-item > .ant-collapse-header {
|
963 |
padding: 8px 12px;
|
@@ -966,16 +967,93 @@ css = """
|
|
966 |
font-weight: 500;
|
967 |
}
|
968 |
.thinking-content .ant-collapse-content > .ant-collapse-content-box {
|
969 |
-
padding:
|
970 |
-
background:
|
971 |
-
border-radius: 0
|
|
|
|
|
|
|
|
|
972 |
font-size: 13px;
|
973 |
color: #667788;
|
974 |
-
line-height: 1.
|
975 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
976 |
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
|
977 |
}
|
978 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
979 |
/* 图片预览和展示样式 */
|
980 |
.image-preview-container {
|
981 |
background: #fafafa;
|
@@ -1306,30 +1384,45 @@ with gr.Blocks(css=css, fill_width=True) as demo:
|
|
1306 |
const thinking_done = bubble?.meta?.thinking_done || false
|
1307 |
|
1308 |
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
1309 |
thinking_collapse: {
|
1310 |
items: thinking_content || is_thinking ? [{
|
1311 |
key: '1',
|
1312 |
label: is_thinking ? '🤔 正在思考...' : '🤔 思考过程',
|
1313 |
-
children:
|
1314 |
}] : [],
|
1315 |
-
|
1316 |
-
display: (thinking_content || is_thinking) ? 'block' : 'none',
|
1317 |
-
marginBottom: thinking_content || is_thinking ? '12px' : '0'
|
1318 |
-
},
|
1319 |
size: 'small',
|
1320 |
ghost: true
|
1321 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
1322 |
answer: {
|
1323 |
value: content
|
1324 |
},
|
1325 |
canceled: bubble.meta?.canceled ? undefined : { style: { display: 'none' } }
|
1326 |
}
|
1327 |
}"""):
|
1328 |
-
# Thinking区域 -
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1333 |
|
1334 |
# 回答内容
|
1335 |
ms.Markdown(
|
|
|
956 |
.thinking-content .ant-collapse {
|
957 |
background: linear-gradient(135deg, #f6f9fc 0%, #f0f4f8 100%);
|
958 |
border: 1px solid #e1e8ed;
|
959 |
+
border-radius: 8px 8px 0 0;
|
960 |
+
border-bottom: none;
|
961 |
+
margin-bottom: 0;
|
962 |
}
|
963 |
.thinking-content .ant-collapse > .ant-collapse-item > .ant-collapse-header {
|
964 |
padding: 8px 12px;
|
|
|
967 |
font-weight: 500;
|
968 |
}
|
969 |
.thinking-content .ant-collapse-content > .ant-collapse-content-box {
|
970 |
+
padding: 0;
|
971 |
+
background: transparent;
|
972 |
+
border-radius: 0;
|
973 |
+
}
|
974 |
+
|
975 |
+
/* Thinking markdown 内容样式 */
|
976 |
+
.thinking-markdown-content {
|
977 |
font-size: 13px;
|
978 |
color: #667788;
|
979 |
+
line-height: 1.6;
|
980 |
+
}
|
981 |
+
|
982 |
+
.thinking-markdown-content h1,
|
983 |
+
.thinking-markdown-content h2,
|
984 |
+
.thinking-markdown-content h3,
|
985 |
+
.thinking-markdown-content h4,
|
986 |
+
.thinking-markdown-content h5,
|
987 |
+
.thinking-markdown-content h6 {
|
988 |
+
color: #5a6c7d;
|
989 |
+
margin: 12px 0 8px 0;
|
990 |
+
font-weight: 600;
|
991 |
+
}
|
992 |
+
|
993 |
+
.thinking-markdown-content h1 { font-size: 16px; }
|
994 |
+
.thinking-markdown-content h2 { font-size: 15px; }
|
995 |
+
.thinking-markdown-content h3 { font-size: 14px; }
|
996 |
+
.thinking-markdown-content h4,
|
997 |
+
.thinking-markdown-content h5,
|
998 |
+
.thinking-markdown-content h6 { font-size: 13px; }
|
999 |
+
|
1000 |
+
.thinking-markdown-content p {
|
1001 |
+
margin: 8px 0;
|
1002 |
+
}
|
1003 |
+
|
1004 |
+
.thinking-markdown-content code {
|
1005 |
+
background: #f8f9fa;
|
1006 |
+
border: 1px solid #e9ecef;
|
1007 |
+
border-radius: 3px;
|
1008 |
+
padding: 2px 4px;
|
1009 |
+
font-size: 12px;
|
1010 |
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
|
1011 |
}
|
1012 |
|
1013 |
+
.thinking-markdown-content pre {
|
1014 |
+
background: #f8f9fa;
|
1015 |
+
border: 1px solid #e9ecef;
|
1016 |
+
border-radius: 4px;
|
1017 |
+
padding: 12px;
|
1018 |
+
overflow-x: auto;
|
1019 |
+
margin: 8px 0;
|
1020 |
+
}
|
1021 |
+
|
1022 |
+
.thinking-markdown-content pre code {
|
1023 |
+
background: transparent;
|
1024 |
+
border: none;
|
1025 |
+
padding: 0;
|
1026 |
+
font-size: 12px;
|
1027 |
+
}
|
1028 |
+
|
1029 |
+
.thinking-markdown-content blockquote {
|
1030 |
+
border-left: 3px solid #6A57FF;
|
1031 |
+
padding-left: 12px;
|
1032 |
+
margin: 8px 0;
|
1033 |
+
color: #666;
|
1034 |
+
font-style: italic;
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
.thinking-markdown-content ul,
|
1038 |
+
.thinking-markdown-content ol {
|
1039 |
+
margin: 8px 0;
|
1040 |
+
padding-left: 20px;
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
.thinking-markdown-content li {
|
1044 |
+
margin: 4px 0;
|
1045 |
+
}
|
1046 |
+
|
1047 |
+
.thinking-markdown-content strong {
|
1048 |
+
color: #333;
|
1049 |
+
font-weight: 600;
|
1050 |
+
}
|
1051 |
+
|
1052 |
+
.thinking-markdown-content em {
|
1053 |
+
color: #666;
|
1054 |
+
font-style: italic;
|
1055 |
+
}
|
1056 |
+
|
1057 |
/* 图片预览和展示样式 */
|
1058 |
.image-preview-container {
|
1059 |
background: #fafafa;
|
|
|
1384 |
const thinking_done = bubble?.meta?.thinking_done || false
|
1385 |
|
1386 |
return {
|
1387 |
+
thinking_container: {
|
1388 |
+
style: {
|
1389 |
+
display: (thinking_content || is_thinking) ? 'block' : 'none',
|
1390 |
+
marginBottom: thinking_content || is_thinking ? '12px' : '0'
|
1391 |
+
}
|
1392 |
+
},
|
1393 |
thinking_collapse: {
|
1394 |
items: thinking_content || is_thinking ? [{
|
1395 |
key: '1',
|
1396 |
label: is_thinking ? '🤔 正在思考...' : '🤔 思考过程',
|
1397 |
+
children: '' // 我们将使用独立的 Markdown 组件
|
1398 |
}] : [],
|
1399 |
+
defaultActiveKey: thinking_content || is_thinking ? ['1'] : [],
|
|
|
|
|
|
|
1400 |
size: 'small',
|
1401 |
ghost: true
|
1402 |
},
|
1403 |
+
thinking_markdown: {
|
1404 |
+
value: thinking_content || (is_thinking ? '思考中...' : ''),
|
1405 |
+
style: {
|
1406 |
+
display: (thinking_content || is_thinking) ? 'block' : 'none'
|
1407 |
+
}
|
1408 |
+
},
|
1409 |
answer: {
|
1410 |
value: content
|
1411 |
},
|
1412 |
canceled: bubble.meta?.canceled ? undefined : { style: { display: 'none' } }
|
1413 |
}
|
1414 |
}"""):
|
1415 |
+
# Thinking区域 - 可折叠显示,支持markdown渲染
|
1416 |
+
with ms.Div(as_item="thinking_container", elem_classes="thinking-content"):
|
1417 |
+
antd.Collapse(
|
1418 |
+
as_item="thinking_collapse",
|
1419 |
+
elem_style=dict(marginBottom="0")
|
1420 |
+
)
|
1421 |
+
with ms.Div(elem_style=dict(padding="12px 16px 16px 16px", background="#fff", borderRadius="0 0 6px 6px", border="1px solid #e1e8ed", borderTop="none")):
|
1422 |
+
ms.Markdown(
|
1423 |
+
as_item="thinking_markdown",
|
1424 |
+
elem_classes="thinking-markdown-content"
|
1425 |
+
)
|
1426 |
|
1427 |
# 回答内容
|
1428 |
ms.Markdown(
|