Skip to main content

Streamlit custom component that offers chat input box for messages - with files upload widget

Project description

streamlit-chat-input-fileupload

A Streamlit custom component providing a chat input box with integrated file upload.

Installation

pip install streamlit-chat-input-fileupload

Usage

import streamlit as st
from streamlit_chat_input_fileupload import chat_input_with_upload

user_input = chat_input_with_upload(placeholder="Send a message...")

if user_input:
    st.write(f"Message: {user_input['text']}")

    if user_input["file"]:
        st.write(f"File: {user_input['file']['name']}")
        # user_input["file"]["data"] contains raw bytes

API

chat_input_with_upload()

chat_input_with_upload(
    placeholder="Send a message...",  # Input placeholder text
    disabled=False,                   # Disable the input
    key=None,                         # Unique component key
)

Returns None or dict:

  • text (str): Message text
  • file (dict or None): {name, type, size, data} where data is bytes

Sending Files to User

Use Streamlit's built-in st.download_button to send files back to the user:

import streamlit as st

# Text file
st.download_button(
    label="Download Report",
    data="Report content here",
    file_name="report.txt",
    mime="text/plain",
)

# Binary file (e.g., generated image, PDF)
st.download_button(
    label="Download Image",
    data=image_bytes,
    file_name="output.png",
    mime="image/png",
)

# CSV data
import pandas as pd
df = pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})
st.download_button(
    label="Download CSV",
    data=df.to_csv(index=False),
    file_name="data.csv",
    mime="text/csv",
)

Features

  • Text input with send button
  • File attachment button
  • Auto light/dark theme detection
  • Supports images and documents

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

File details

Details for the file streamlit_chat_input_fileupload-0.6.15-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_chat_input_fileupload-0.6.15-py3-none-any.whl
Algorithm Hash digest
SHA256 2386338a85f2c10000d678d2e91057e9aecaddf4f2cb6a3b9fab577aea95456c
MD5 aa44670583e4528d40c3e78494f639ef
BLAKE2b-256 cc0635b4fb464e15bf536de7eaa049bfbed710bb1829e3e11c3d49942db02245

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