Skip to content

image-20250411222716731

python
import streamlit as st
# 模拟流式输出
def generate_output():
    for i in range(1, 6):
        time.sleep(1)  # 模拟耗时操作
        yield f"步骤 {i}: 处理中...\n"

# 显示流式输出
output_placeholder = st.empty()  # 创建一个占位符
result = ""
for chunk in generate_output():
    result += chunk  # 累积内容
    output_placeholder.markdown(result)  # 更新占位符内容