Streamlit学习笔记01:st.set_page_config()

st.set_page_config语法:
st.set_page_config(page_title=None, page_icon=None, layout=“centered”, initial_sidebar_state=“auto”, menu_items=None)

参数说明:

  • page_title (字符 或 None)

页标题,显示在浏览器标签上。如果为None,则缺省为脚本的文件名 (“app.py” 将显示为 “app • Streamlit”).

  • page_icon (Anything supported by st.image or str or None)

网页图标. 除st.image (如 URLs 或 numpy数组)支持的类型外, 您可以传入emoji 作为字符串 (“🦈”) 或者 a shortcode ("🦈"). 如果您觉得足够幸运, 试试 “random” 来获取一个随机的emoji! Emoji icons由Twemoji免费提供,从MaxCDN载入。

  • layout (“centered” or “wide”)

页面元素布局,缺省为 “centered”; “wide” 将使用整个屏幕.

  • initial_sidebar_state (“auto” or “expanded” or “collapsed”)

设置边栏的初始状态. 缺省为 “auto”, 将在移动迟寸的设备上隐藏边栏, 否则显示。 “expanded” 设置为初始显示; “collapsed” 设置为折叠。

  • menu_items (dict)

配置页面顶部最右端的菜单。包括:

  • “Get help”: str or None The URL this menu item should point to. If None, hides this menu item.
  • “Report a Bug”: 字符 or None。 该菜单项指向的URL. 如果为None, 则隐藏该菜单项.
  • “About”: str or None A markdown string to show in the About dialog. If None, only shows Streamlit’s default About text.

注意:set_page_config() 在每个APP里智能调用一次,且必须在脚本中的第一行,否则将报错:

StreamlitAPIException: set_page_config() can only be called once per app, and must be called as the first Streamlit command in your script.
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
from transformers import AutoModel, AutoTokenizer import streamlit as st from streamlit_chat import message st.set_page_config( page_title="ChatGLM-6b 演示", page_icon=":robot:" ) @st.cache_resource def get_model(): tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda() model = model.eval() return tokenizer, model MAX_TURNS = 20 MAX_BOXES = MAX_TURNS * 2 def predict(input, max_length, top_p, temperature, history=None): tokenizer, model = get_model() if history is None: history = [] with container: if len(history) > 0: if len(history)>MAX_BOXES: history = history[-MAX_TURNS:] for i, (query, response) in enumerate(history): message(query, avatar_style="big-smile", key=str(i) + "_user") message(response, avatar_style="bottts", key=str(i)) message(input, avatar_style="big-smile", key=str(len(history)) + "_user") st.write("AI正在回复:") with st.empty(): for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p, temperature=temperature): query, response = history[-1] st.write(response) return history container = st.container() # create a prompt text for the text generation prompt_text = st.text_area(label="用户命令输入", height = 100, placeholder="请在这儿输入您的命令") max_length = st.sidebar.slider( 'max_length', 0, 4096, 2048, step=1 ) top_p = st.sidebar.slider( 'top_p', 0.0, 1.0, 0.6, step=0.01 ) temperature = st.sidebar.slider( 'temperature', 0.0, 1.0, 0.95, step=0.01 ) if 'state' not in st.session_state: st.session_state['state'] = [] if st.button("发送", key="predict"): with st.spinner("AI正在思考,请稍等........"): # text generation st.session_state["state"] = predict(prompt_text, max_length, top_p, temperature, st.session_state["state"])逐句解析代码
05-11
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

狮弟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值