上传文件至「/」
This commit is contained in:
11
01-Streamlit-基本语法.py
Normal file
11
01-Streamlit-基本语法.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import streamlit as st
|
||||
|
||||
st.title("Streamlit 实例")
|
||||
|
||||
st.write("这是一个简单的 Streamlit 应用程序。")
|
||||
|
||||
st.markdown("# 这是一个一级标题")
|
||||
st.markdown("## 这是一个二级标题")
|
||||
st.markdown("### 这是一个三级标题")
|
||||
st.markdown("#### 这是一个四级标题")
|
||||
st.markdown("这是正文")
|
||||
7
02-streamlit-表格组件.py
Normal file
7
02-streamlit-表格组件.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import streamlit as st
|
||||
|
||||
user_data=[{"编号":1,"姓名":"小王","年龄":18,"手机号":123456789},
|
||||
{"编号":2,"姓名":"小李","年龄":18,"手机号":123456789},
|
||||
{"编号":3,"姓名":"小张","年龄":18,"手机号":123456789}]
|
||||
|
||||
st.table(user_data)
|
||||
6
03-streamlit-输入组件.py
Normal file
6
03-streamlit-输入组件.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import streamlit as st
|
||||
|
||||
|
||||
st.text_input(label="姓名:")
|
||||
st.text_input(label="年龄:")
|
||||
st.text_input(label="密码:",type="password")
|
||||
8
04-streamlit-聊天输入.py
Normal file
8
04-streamlit-聊天输入.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import streamlit as st
|
||||
from streamlit import user
|
||||
|
||||
user_input=st.chat_input()
|
||||
|
||||
if user_input:
|
||||
with st.chat_message("user"):
|
||||
st.write(user_input)
|
||||
22
05-streamlit-会话状态.py
Normal file
22
05-streamlit-会话状态.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import streamlit as st
|
||||
|
||||
# 会话管理状态:在程序执行过程中,无论代码重新运行多少次,会话状态里面的变量都会保存
|
||||
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"])
|
||||
|
||||
# 聊天输入
|
||||
print("用户输入前打印————————")
|
||||
user_input = st.chat_input("请输入你的问题:")
|
||||
print(f"用户输入后打印————————{user_input}")
|
||||
|
||||
if user_input:
|
||||
st.session_state.messages.append({"role": "user", "content": user_input})
|
||||
with st.chat_message("user"):
|
||||
st.write(user_input)
|
||||
Reference in New Issue
Block a user