Streamlit custom component that offers chat input box for messages - with files upload widget
Project description
streamlit-chat-input-fileupload
A Streamlit custom component that extends the standard st.chat_input with file upload capability. Drop-in replacement for building chat interfaces that need document and image attachments.
Features
- Combined text input and file upload in a single component
- Paperclip button for file selection with filename indicator
- Supports images (PNG, JPG, GIF, WebP) and documents (PDF, CSV, TXT, XLSX, DOCX, MD, HTML)
- Auto-detects light/dark theme from Streamlit's settings
- Returns message text and file data (as bytes) in a single dict
- Built with Streamlit Components v2 API
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 textfile(dict or None):{name, type, size, data}wheredatais 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",
)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_chat_input_fileupload-0.6.16-py3-none-any.whl.
File metadata
- Download URL: streamlit_chat_input_fileupload-0.6.16-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f88ff2bce4c620d8f3de7da4e611dcc35b60aa1788a7be03feb1aa1e81fd944
|
|
| MD5 |
3baa6a30e4c7a972bb21caa72e5ea062
|
|
| BLAKE2b-256 |
232b7716e28657797cb002498a4d6e34bf8c939ff7537dc8adbb3cfee9ea63ab
|