Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1899,39 +1899,6 @@ elif st.session_state.get("_chat_cleared"):
|
|
| 1899 |
# 用户主动清空,不从数据库恢复
|
| 1900 |
del st.session_state["_chat_cleared"]
|
| 1901 |
|
| 1902 |
-
# 欢迎页占位(有消息时隐藏)
|
| 1903 |
-
_welcome_hero = st.empty()
|
| 1904 |
-
if not st.session_state.messages:
|
| 1905 |
-
# 无消息时显示欢迎页
|
| 1906 |
-
with _welcome_hero.container():
|
| 1907 |
-
st.markdown(
|
| 1908 |
-
"""
|
| 1909 |
-
<div class="welcome-marker" style="text-align:center; color:#888;">
|
| 1910 |
-
<div style="font-size:48px; margin-bottom:12px;">🤖</div>
|
| 1911 |
-
<div style="font-size:18px; font-weight:600; margin-bottom:8px;">欢迎使用智答 AI 助手</div>
|
| 1912 |
-
<div style="font-size:14px; line-height:1.8; margin-bottom:20px;">
|
| 1913 |
-
🌐 <b>联网模式</b> —— 大模型 + 网络搜索,实时回答<br>
|
| 1914 |
-
📚 <b>知识库模式</b> —— 上传文档,基于私有知识回答
|
| 1915 |
-
</div>
|
| 1916 |
-
<div style="color:#999; font-size:13px; margin-bottom:12px;">💡 试试这些问题</div>
|
| 1917 |
-
</div>
|
| 1918 |
-
""",
|
| 1919 |
-
unsafe_allow_html=True,
|
| 1920 |
-
)
|
| 1921 |
-
# 快捷问题 - 电脑端横向3个,手机端通过CSS控制
|
| 1922 |
-
_quick_questions = [
|
| 1923 |
-
"今天有什么热点新闻",
|
| 1924 |
-
"用Python写快速排序",
|
| 1925 |
-
"解释RAG技术是什么",
|
| 1926 |
-
]
|
| 1927 |
-
# 电脑端横向3列
|
| 1928 |
-
_q_cols = st.columns(3)
|
| 1929 |
-
for i, qq in enumerate(_quick_questions):
|
| 1930 |
-
with _q_cols[i]:
|
| 1931 |
-
if st.button(f"💬 {qq}", key=f"quick_q{i}", use_container_width=True, type="secondary"):
|
| 1932 |
-
st.session_state["_quick_question"] = qq
|
| 1933 |
-
st.rerun()
|
| 1934 |
-
|
| 1935 |
|
| 1936 |
@st.fragment
|
| 1937 |
def _chat_fragment():
|
|
@@ -1941,6 +1908,36 @@ def _chat_fragment():
|
|
| 1941 |
_top_k = st.session_state.get("sel_topk", 5)
|
| 1942 |
_threshold = st.session_state.get("sel_threshold", 0.25)
|
| 1943 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1944 |
# 消息容器 - 不设固定高度,由外层CSS控制滚动
|
| 1945 |
chat_box = st.container()
|
| 1946 |
q = st.chat_input("问问智答AI助手", key="chat_input_v3")
|
|
|
|
| 1899 |
# 用户主动清空,不从数据库恢复
|
| 1900 |
del st.session_state["_chat_cleared"]
|
| 1901 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1902 |
|
| 1903 |
@st.fragment
|
| 1904 |
def _chat_fragment():
|
|
|
|
| 1908 |
_top_k = st.session_state.get("sel_topk", 5)
|
| 1909 |
_threshold = st.session_state.get("sel_threshold", 0.25)
|
| 1910 |
|
| 1911 |
+
# 欢迎页(无消息时显示,放在 fragment 内避免整页刷新)
|
| 1912 |
+
_welcome_hero = st.empty()
|
| 1913 |
+
if not st.session_state.messages:
|
| 1914 |
+
with _welcome_hero.container():
|
| 1915 |
+
st.markdown(
|
| 1916 |
+
"""
|
| 1917 |
+
<div class="welcome-marker" style="text-align:center; color:#888;">
|
| 1918 |
+
<div style="font-size:48px; margin-bottom:12px;">🤖</div>
|
| 1919 |
+
<div style="font-size:18px; font-weight:600; margin-bottom:8px;">欢迎使用智答 AI 助手</div>
|
| 1920 |
+
<div style="font-size:14px; line-height:1.8; margin-bottom:20px;">
|
| 1921 |
+
🌐 <b>联网模式</b> —— 大模型 + 网络搜索,实时回答<br>
|
| 1922 |
+
📚 <b>知识库模式</b> —— 上传文档,基于私有知识回答
|
| 1923 |
+
</div>
|
| 1924 |
+
<div style="color:#999; font-size:13px; margin-bottom:12px;">💡 试试这些问题</div>
|
| 1925 |
+
</div>
|
| 1926 |
+
""",
|
| 1927 |
+
unsafe_allow_html=True,
|
| 1928 |
+
)
|
| 1929 |
+
# 快捷问题 - 在 fragment 内部,点击只触发 fragment 刷新
|
| 1930 |
+
_quick_questions = [
|
| 1931 |
+
"今天有什么热点新闻",
|
| 1932 |
+
"用Python写快速排序",
|
| 1933 |
+
"解释RAG技术是什么",
|
| 1934 |
+
]
|
| 1935 |
+
_q_cols = st.columns(3)
|
| 1936 |
+
for i, qq in enumerate(_quick_questions):
|
| 1937 |
+
with _q_cols[i]:
|
| 1938 |
+
if st.button(f"💬 {qq}", key=f"quick_q{i}", use_container_width=True, type="secondary"):
|
| 1939 |
+
st.session_state["_quick_question"] = qq
|
| 1940 |
+
|
| 1941 |
# 消息容器 - 不设固定高度,由外层CSS控制滚动
|
| 1942 |
chat_box = st.container()
|
| 1943 |
q = st.chat_input("问问智答AI助手", key="chat_input_v3")
|