Skip to main content

English | 日本語

Demo

Demo

Streamlit Multimodal Chat Input

A multimodal chat input component for Streamlit that supports text input, image upload, and voice input.

Note: Voice and image features require HTTPS or localhost environment to function properly.

Features

  • 📝 Text Input: Same usability as st.chat_input
  • 🖼️ Image File Upload: Supports jpg, png, gif, webp
  • 🎤 Voice Input: Web Speech API / server-side OpenAI Whisper support
  • 🔒 Input Validation: File count, file size, MIME/content, and parameter validation
  • 🎨 Streamlit Standard Theme: Fully compatible design
  • 🔄 Drag & Drop: File drag and drop support
  • ⌨️ Ctrl+V: Paste images from clipboard
  • 🚨 Inline Errors: User-safe inline messages
  • ⚙️ Customizable: Rich configuration options

Installation

pip install st-chat-input-multimodal

Basic Usage

import streamlit as st
from st_chat_input_multimodal import multimodal_chat_input

# Basic usage
result = multimodal_chat_input()

if result:
    # Display text
    if result['text']:
        st.write(f"Text: {result['text']}")
    
    # Display uploaded files
    if result['files']:
        for file in result['files']:
            import base64
            base64_data = file['data'].split(',')[1] if ',' in file['data'] else file['data']
            image_bytes = base64.b64decode(base64_data)
            st.image(image_bytes, caption=file['name'])
    
    # Display voice input metadata
    if result.get('audio_metadata'):
        st.write(f"Voice input used: {result['audio_metadata']['used_voice_input']}")

Advanced Usage

Voice Input Features

# Enable voice input
result = multimodal_chat_input(
    enable_voice_input=True,
    voice_recognition_method="web_speech",  # or "openai_whisper"
    voice_language="ja-JP",
    max_recording_time=60
)

# Using OpenAI Whisper on the server side
# Preferred: set OPENAI_API_KEY in the Python environment
result = multimodal_chat_input(
    enable_voice_input=True,
    voice_recognition_method="openai_whisper",
    voice_language="ja-JP"
)

When openai_whisper is selected, recorded audio is sent to the Python backend for transcription. The API key is used only on the server side and is never forwarded to the browser.

Voice Transcription Error Handling

Runtime voice-transcription failures are converted into user-safe inline messages instead of exposing raw backend exception details.

  • Voice transcription is not available in this app.: Whisper is not available for the current app configuration.
  • Recorded audio could not be processed. Please try recording again.: The recorded audio payload was invalid or unreadable.
  • Voice transcription is temporarily unavailable. Please try again.: Temporary API or network issue.
  • Voice transcription failed. Please try again.: Final fallback for unexpected runtime errors.

Developer-facing parameter validation still raises ValueError during multimodal_chat_input(...) initialization so configuration mistakes fail fast.

Custom Configuration

result = multimodal_chat_input(
    placeholder="Please enter your message...",
    max_chars=500,
    accepted_file_types=["jpg", "png", "gif", "webp"],
    max_file_size_mb=10,
    max_files=5,
    disabled=False,
    key="custom_chat_input"
)

max_chars, max_file_size_mb, and max_files must be positive integers. max_recording_time must be between 1 and 300, and voice_recognition_method must be either "web_speech" or "openai_whisper". Uploaded images are validated by extension and file signature, and displayed filenames are sanitized before rendering.

Chat Usage

import streamlit as st
import base64
from st_chat_input_multimodal import multimodal_chat_input

# Page configuration
st.set_page_config(
    page_title="Multimodal Chat Input Demo",
    page_icon="💬",
    layout="wide"
)

st.subheader("💭 Multimodal Chat Input Demo")
st.markdown("Simulate a chat application with voice input and file upload.")

# Manage history in session state
if "chat_history" not in st.session_state:
    st.session_state.chat_history = []

# Input for new messages
chat_result = multimodal_chat_input(
    placeholder="Enter chat message...",
    enable_voice_input=True,  # Enable voice input for chat as well
    key="chat_input"
)
if chat_result:
    st.session_state.chat_history.append(chat_result)

# Display chat history
if st.session_state.chat_history:
    for i, message in enumerate(st.session_state.chat_history):
        with st.chat_message("user"):
            if message.get("text"):
                st.write(message["text"])
            
            if message.get("files"):
                for file in message["files"]:
                    try:
                        base64_data = file['data'].split(',')[1] if ',' in file['data'] else file['data']
                        image_bytes = base64.b64decode(base64_data)
                        st.image(image_bytes, caption=file['name'], width=200)
                    except:
                        st.write(f"📎 {file['name']}")
            
            # Display voice input information
            if message.get("audio_metadata") and message["audio_metadata"]["used_voice_input"]:
                st.caption(f"🎤 Voice input ({message['audio_metadata']['transcription_method']})")


# Clear history
if st.button("Clear History"):
    st.session_state.chat_history = []
    st.rerun()

Example Chat App

streamlit-chatbot example

License

MIT License

Author

tsuzukia21

Release files for st-chat-input-multimodal 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for st-chat-input-multimodal 2.0.0
File Size Uploaded
st_chat_input_multimodal-2.0.0.tar.gz 137.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for st-chat-input-multimodal 2.0.0
File Interpreter ABI Platform
st_chat_input_multimodal-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 273.5 kB

Release files / st_chat_input_multimodal-2.0.0.tar.gz

Download URL st_chat_input_multimodal-2.0.0.tar.gz
Size 137.7 kB
Tags Source
SHA-256 checksum
How to use checksums
aa6c07ed5f4ce7de58b810925b121cd349ab6e379e27532ede2e668de19bfd79
BLAKE2b-256 checksum
How to use checksums
32e11a99e876ecc8441149a99cc0bcb0d83f9ee2d31574b31cad49869022e975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 29, 2026.

Transparency log

Release files / st_chat_input_multimodal-2.0.0-py3-none-any.whl

Download URL st_chat_input_multimodal-2.0.0-py3-none-any.whl
Size 135.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb48faee816702283992a7707380a71ea03dd082cc28b4b62301c3480cf937ca
BLAKE2b-256 checksum
How to use checksums
bd6658e254d703229ac425f4f9870b58b2441937f7cfb88cc9b03db09807afe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page