Python应用开发——30天学习Streamlit Python包进行APP的构建(13)

embedded/2024/9/23 11:17:48/

st.chat_input

显示聊天输入窗口小部件。

Function signature[source]

st.chat_input(placeholder="Your message", *, key=None, max_chars=None, disabled=False, on_submit=None, args=None, kwargs=None)

Returns

(str or None)

The current (non-empty) value of the text input widget on the last run of the app. Otherwise, None.

Parameters

placeholder (str)

A placeholder text shown when the chat input is empty. Defaults to "Your message". For accessibility reasons, you should not use an empty string.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

max_chars (int or None)

The maximum number of characters that can be entered. If None (default), there will be no maximum.

disabled (bool)

Whether the chat input should be disabled. Defaults to False.

on_submit (callable)

An optional callback invoked when the chat input's value is submitted.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

代码

应用程序主体中使用 st.chat_input 时,它将被固定在页面底部。

python">import streamlit>streamlit as stprompt = st.chat_input("Say something")
if prompt:st.write(f"User has sent the following prompt: {prompt}")

这段代码使用了Streamlit库来创建一个简单的聊天输入界面。用户可以在输入框中输入内容,然后点击发送按钮。当用户输入内容后,代码会检查输入内容是否存在,如果存在则会将用户输入的内容显示在屏幕上。

这里每一次输入都会替换掉原来输入的内容。 

 聊天输入法还可以嵌套到任何布局容器(容器、列、标签、侧边栏等)中,从而在线使用。创建嵌入到其他内容旁边的聊天界面,或拥有多个聊天机器人!

python">import streamlit>streamlit as stwith st.sidebar:messages = st.container(height=300)if prompt := st.chat_input("Say something"):messages.chat_message("user").write(prompt)messages.chat_message("assistant").write(f"Echo: {prompt}")

这段代码使用了Streamlit库来创建一个简单的聊天界面。首先,通过`import streamlit>streamlit as st`导入了Streamlit库。然后,使用`with st.sidebar`创建了一个侧边栏,并在其中创建了一个高度为300的容器`messages`。接着,使用`st.chat_input("Say something")`创建了一个聊天输入框,用户可以在其中输入消息。如果用户输入了消息(使用了walrus运算符`:=`来检查是否有输入),则会在`messages`容器中显示用户输入的消息和助手的回复,助手回复的内容是用户输入消息的回显。

 有关 st.chat_input 和 st.chat_message API 的概述,请观看 Streamlit 高级开发人员宣传员 Chanin Nantasenamat (@dataprofessor) 制作的视频教程。

style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box">

http://www.ppmy.cn/embedded/56587.html

相关文章

抖音微短剧小程序入驻指南

一、抖音微短剧小程序类目和准入要求是什么? 可以明确的告诉你抖音微短剧小程序入驻是需要报白的,属于定邀类目,官方准入要求如下: 类目要求:文娱-微短剧 定向准入,填写“【微短剧】类目定向邀约申请表”…

Java跳出循环的四种方式

1、continue,break,return continue:跳出当前层循环的当前语句,执行当前层循环的下一条语句。   continue标签 break:跳出当前层循环。 break标签:多层循环时,跳到具体某层循环。 return:结束所有循环…

Selenium的这些自动化测试技巧你知道几个?

Selenium自动化测试技巧 与以前瀑布式开发模式不同,现在软件测试人员具有使用自动化工具执行测试用例套件的优势,而以前,测试人员习惯于通过测试脚本执行来完成测试。 但自动化测试的目的不是完全摆脱手动测试,而是最大程度地减少…

springboot 配置加密,jasypt加解密命令

位置:Maven仓库中\org\jasypt\jasypt\1.9.3 java -cp jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input123456 passwordmysalt algorithmPBEWithMD5andDES ----ENVIRONMENT----------------- Runtime: Oracle Corporation Java HotSpot™…

海外盲盒小程序搭建过程的最大挑战:市场竞争与用户体验

一、引言 在海外市场搭建盲盒小程序时,除了技术实施和本地化适应外,市场竞争与用户体验也是企业面临的重要挑战。本文将详细探讨这两个方面的挑战,并提出相应的解决策略。 二、市场竞争的挑战 1. 竞品分析与定位 海外市场中的盲盒小程序竞…

Cesium与Three相机同步(3)

Cesium与Three融合的案例demo <!DOCTYPE html> <html lang"en" class"dark"><head><meta charset"UTF-8"><link rel"icon" href"/favicon.ico"><meta name"viewport" content&q…

WebStorm 2024 for Mac JavaScript前端开发工具

Mac分享吧 文章目录 效果一、下载软件二、开始安装1、双击运行软件&#xff08;适合自己的M芯片版或Intel芯片版&#xff09;&#xff0c;将其从左侧拖入右侧文件夹中&#xff0c;等待安装完毕2、应用程序显示软件图标&#xff0c;表示安装成功3、打开访达&#xff0c;点击【文…

Docker 部署 Nacos v2.3.2 版本

文章目录 Github官网文档Nacos 生态图Nacos Dockerdocker-compose.ymlapplication.propertiesNacos 官方示例 Github https://github.com/alibaba/nacos 官网 https://nacos.io/ 文档 https://nacos.io/docs/latest/what-is-nacos/ Nacos 生态图 Nacos Docker 镜像&…