st.chat_input() in Streamlit

In Streamlit, chat_input is a specialized input widget used to build chat-style applications such as AI assistants, support bots, or conversational dashboards. It provides a fixed input box at the bottom of the app, similar to ChatGPT or WhatsApp.

What is st.chat_input()?

The st.chat_input() creates a chat message input field where users can type a message and submit it.

It is designed to work with:

Basic Syntax

st.chat_input(placeholder="Your message", key=None, max_chars=None)    

The function has the following parameters:

Example: Create a basic chat input.

Python

# Importing the Streamlit library
import streamlit as st

# Title
st.title("Simple Chat")

# Chat input box
user_input = st.chat_input("Type a message...")

# Display message
if user_input:
    st.write("You said:", user_input)    

What happens:

The output of the above code is shown below:

Chat input in Streamlit