Skip to main content

A Streamlit component that allows you to select from a list of options or enter a custom value.

Project description

PyPI Downloads PyPI version

Streamlit free text select

This component implements a selectbox that allows free text input. It is based on React-Select's 'Select' component.

Installation

pip install streamlit-free-text-select

Usage (Example 1)

import streamlit as st
from streamlit_smarttext_input import st_smart_text_input

st.set_page_config(page_title="SmartText Input Demo", layout="centered")
st.title("Streamlit SmartText Input Test")

# Options to test with
options = ["Toyota", "BMW", "Tesla", "Ford", "Audi", "Mercedes", "Honda"]


# Call the custom component
value = st_smart_text_input(
    label="Choose or Type a Fruit or Greeting",
    options=options,
    index=None,
    placeholder="Start typing and press Enter...",
    delay=200,
    disabled=False,
    label_visibility="visible",
)

# Display what was selected or typed
if value:
    if value.lower() in [o.lower() for o in options]:
        st.info(f"'{value}' is a known car brand from the list.")
    elif value.lower() in ["hi", "hey", "hello"]:
        st.info("Hello, I am a Python package crafted by [Ankit Guria](https://github.com/ankitguria).")
    else:
        st.warning(f"'{value}' is a new input. You can add this to the list!")

# UI Divider
st.markdown("---")
st.caption("Press ⏎ Enter after typing to trigger input capture.")

Usage (Example 1)

import streamlit as st
from streamlit_smarttext_input import st_smart_text_input

st.set_page_config(page_title="SmartText Chat Thread", layout="centered")
st.title("Streamlit SmartText Chat")

# Initialize chat history
if "chat_history" not in st.session_state:
    st.session_state.chat_history = []

# Options (can be dynamic)
options = ["hi", "hello", "help", "bye", "thanks", "how are you?"]

# Display existing chat
st.markdown("### Conversation")
for i, msg in enumerate(st.session_state.chat_history):
    is_user = msg["sender"] == "user"
    with st.chat_message("user" if is_user else "assistant"):
        st.markdown(msg["text"])

# User input (free-form or from options)
user_input = st_smart_text_input(
    label="Type your message",
    options=options,
    placeholder="Ask something or say hello...",
    delay=100,
    disabled=False,
    label_visibility="collapsed",
    key=f"chat_input_{len(st.session_state.chat_history)}"

)

# When user submits a message
if user_input:
    # Add user message to history
    st.session_state.chat_history.append({
        "sender": "user",
        "text": user_input,
    })

    # Simple bot logic (replace with your own model later)
    if user_input.lower() in ["hi", "hello", "hey"]:
        bot_reply = " Hello, I am a Python package crafted by [Ankit Guria](https://github.com/ankit142)! How can I help you today?"
    elif "help" in user_input.lower():
        bot_reply = "Sure! I'm here to assist. Ask me anything."
    elif user_input.lower() in ["bye", "goodbye"]:
        bot_reply = " Goodbye! Have a great day."
    else:
        bot_reply = f"I heard you say: '{user_input}'"

    # Add bot reply to history
    st.session_state.chat_history.append({
        "sender": "bot",
        "text": bot_reply,
    })

    # Force rerun to refresh chat display and clear input
    st.rerun()

demo

Docs

Parameters

  • label : str A short label explaining to the user what this input is for.
  • options : list A list of predefined options to choose from.
  • index : int An optional index to select an option by default, defaults to None.
  • format_func : callable A callable function to format the options, defaults to None.
  • placeholder : str A string to display when the input is empty, defaults to None.
  • disabled : bool Whether the input is disabled, defaults to False.
  • delay : int The time in milliseconds to wait before updating the component, defaults to 300.
  • key : str An optional string to use as the unique key for the widget, defaults to None.
  • label_visibility : str The visibility of the label, defaults to "visible". Options are "visible", "hidden", "collapsed".

Returns str or None The value of the free text select input.

Contributors

	</tr>
<tbody>
Ankit Guria
Ankit Guria

Release Notes

  • 0.0.5: Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_smart_text_input-1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_smart_text_input-1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_smart_text_input-1.0.tar.gz.

File metadata

File hashes

Hashes for streamlit_smart_text_input-1.0.tar.gz
Algorithm Hash digest
SHA256 325a0210b5a0622a08f10f4355c92f45b93a49b6be8bbb1a9e6cbc838f0f1744
MD5 0c098d4c0102d9d93a79efadde6f1e72
BLAKE2b-256 d6210841b4ca4a6d7d130d3b8eb63b1beba4d3568c72cdad05b13390bc06938d

See more details on using hashes here.

File details

Details for the file streamlit_smart_text_input-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_smart_text_input-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e2b40f4bb058f4de3650aeeb009915f476fc6e98a9ef27c88acb5e825439c13
MD5 d0c7e7b95109af22e26027e8e80fd1d4
BLAKE2b-256 b873cdd4c6f7e3b0d634a71c3c6706d214411b9e0dc8876340baacc5e343cb46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page