上传文件至「/」
This commit is contained in:
12
01.py
Normal file
12
01.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import streamlit as st
|
||||||
|
|
||||||
|
st.title("Streamlit 示例")
|
||||||
|
|
||||||
|
st.write("这是一个简单的 Streamlit 应用程序。")
|
||||||
|
|
||||||
|
st.markdown("#这是一个一级标签")
|
||||||
|
st.markdown("##这是一个二级标签")
|
||||||
|
st.markdown("###这是一个三级标签")
|
||||||
|
st.markdown("####这是一个四级标签")
|
||||||
|
st.markdown("#####这是一个五级标签")
|
||||||
|
st.markdown("这是正文")
|
||||||
5
02.py
Normal file
5
02.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import streamlit as st
|
||||||
|
|
||||||
|
user_data = [{'编号': 1, '姓名': '张三', '年龄': 18},{'编号': 2, '姓名': '李四', '年龄': 19},{'编号': 3, '姓名': '王五', '年龄': 20}]
|
||||||
|
|
||||||
|
st.table(user_data)
|
||||||
15
03.py
Normal file
15
03.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import streamlit as st
|
||||||
|
|
||||||
|
st.text_input(label="姓名")
|
||||||
|
|
||||||
|
st.text_input(label="年龄")
|
||||||
|
|
||||||
|
st.text_input(label="密码", type="password")
|
||||||
|
|
||||||
|
st.text_input(label="数字")
|
||||||
|
|
||||||
|
st.number_input(label="日期")
|
||||||
|
|
||||||
|
st.date_input(label="时间")
|
||||||
|
|
||||||
|
st.text_input("时间")
|
||||||
31
04.py
Normal file
31
04.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from deepseek import get_response
|
||||||
|
# 会话管理状态:在程序执行过程中,无论代码重新运行多少次,会话状态里面的变量都会保存
|
||||||
|
|
||||||
|
st.title("黑马智聊机器人")
|
||||||
|
|
||||||
|
# st.session_state 对象,本质就是json对象字典,
|
||||||
|
if "messages" not in st.session_state:
|
||||||
|
st.session_state["messages"] = [{"role": "assistant", "content": "你好,我是黑马智聊机器人,有什么可以帮助你的么?"}]
|
||||||
|
|
||||||
|
for message in st.session_state.messages:
|
||||||
|
with st.chat_message(message["role"]):
|
||||||
|
st.write(message["content"])
|
||||||
|
# 聊天输入
|
||||||
|
user_input = st.chat_input() #你好
|
||||||
|
|
||||||
|
if user_input:
|
||||||
|
#1 把用户的输入添加到会话状态里面messages中
|
||||||
|
st.session_state.messages.append({"role": "user", "content": user_input})
|
||||||
|
#2 在网页上渲染用户输入
|
||||||
|
with st.chat_message("user"):
|
||||||
|
st.write(user_input)
|
||||||
|
#3 调用deepseek.py中的get_response方法,获取大模型的回复
|
||||||
|
with st.spinner("正在思考中..."):
|
||||||
|
response = get_response(st.session_state.messages)
|
||||||
|
#4 把大模型的回复添加到会话状态里面messages中
|
||||||
|
st.session_state.messages.append({"role": "assistant", "content": response})
|
||||||
|
#5 在网页上渲染大模型的回复
|
||||||
|
with st.chat_message("assistant"):
|
||||||
|
st.write(response)
|
||||||
|
|
||||||
34
05.py
Normal file
34
05.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import streamlit as st
|
||||||
|
from gitdb.pack import write_stream_to_pack
|
||||||
|
|
||||||
|
from deepseek import get_response_stream
|
||||||
|
# 会话管理状态:在程序执行过程中,无论代码重新运行多少次,会话状态里面的变量都会保存
|
||||||
|
|
||||||
|
st.title("黑马智聊机器人")
|
||||||
|
|
||||||
|
# st.session_state 对象,本质就是json对象字典,
|
||||||
|
if "messages" not in st.session_state:
|
||||||
|
st.session_state["messages"] = [{"role": "assistant", "content": "你好,我是黑马智聊机器人,有什么可以帮助你的么?"}]
|
||||||
|
|
||||||
|
for message in st.session_state.messages:
|
||||||
|
with st.chat_message(message["role"]):
|
||||||
|
st.write(message["content"])
|
||||||
|
# 聊天输入
|
||||||
|
user_input = st.chat_input() #你好
|
||||||
|
|
||||||
|
if user_input:
|
||||||
|
#1 把用户的输入添加到会话状态里面messages中
|
||||||
|
st.session_state.messages.append({"role": "user", "content": user_input})
|
||||||
|
#2 在网页上渲染用户输入
|
||||||
|
with st.chat_message("user"):
|
||||||
|
st.write(user_input)
|
||||||
|
#3 调用deepseek.py中的get_response方法,获取大模型的回复
|
||||||
|
# 调用get_response_stream方法,流式获取大模型的回复
|
||||||
|
response = get_response_stream(st.session_state.messages)
|
||||||
|
with st.chat_message("assistant"):
|
||||||
|
st.write_stream(response)
|
||||||
|
|
||||||
|
#4 把大模型的回复添加到会话状态里面messages中
|
||||||
|
st.session_state.messages.append({"role": "assistant", "content": response})
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user