Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
streamlit-chat-prompt
Advanced tools
Streamlit component that allows you to create a chat prompt with paste and image attachment support
A Streamlit component that provides a modern chat-style prompt with image attachment and paste support. This component was built to mimic the style of streamlit.chat_input while expanding functionality with images. Future work may include addition of speech-to-text input.
Author: Tyler House (@tahouse)
pip install streamlit-chat-prompt
import streamlit as st
from streamlit_chat_prompt import prompt
# Create a chat prompt
response = prompt(
name="chat", # Unique name for the prompt
key="chat", # Unique key for the component instance
placeholder="Hi there! What should we talk about?", # Optional placeholder text
main_bottom=True, # Pin prompt to bottom of main area
max_image_size=5 * 1024 * 1024, # Maximum image size (5MB default)
disabled=False, # Optionally disable the prompt
)
# Handle the response
if response:
if response.text:
st.write(f"Message: {response.text}")
if response.images:
for i, img in enumerate(response.images):
st.write(f"Image {i+1}: {img.type} ({img.format})")
Here are some usage patterns, or check out rocktalk for a full working example.
Main Chat Interface
import base64
from io import BytesIO
import streamlit as st
from streamlit_chat_prompt import PromptReturn, prompt, ImageData
from PIL import Image
st.chat_message("assistant").write("Hi there! What should we chat about?")
prompt_return: PromptReturn | None = prompt(
name="foo",
key="chat_prompt",
placeholder="Hi there! What should we chat about?",
main_bottom=True,
)
if prompt_return:
with st.chat_message("user"):
st.write(prompt_return.text)
if prompt_return.images:
for image in prompt_return.images:
st.divider()
image_data: bytes = base64.b64decode(image.data)
st.markdown("Using `st.image`")
st.image(Image.open(BytesIO(image_data)))
# or use markdown
st.divider()
st.markdown("Using `st.markdown`")
st.markdown(f"![Image example](data:image/png;base64,{image.data})")
Dialog Usage and Starting From Existing Message
if st.button(
"Dialog Prompt with Default Value", key=f"dialog_prompt_with_default_button"
):
with open("example_images/vangogh.png", "rb") as f:
image_data = f.read()
image = Image.open(BytesIO(image_data))
base64_image = base64.b64encode(image_data).decode("utf-8")
test_dg(
default_input=PromptReturn(
text="This is a test message with an image",
images=[
ImageData(data=base64_image, type="image/png", format="base64")
],
),
key="dialog_with_default",
)
Main function to create a chat prompt.
Parameters:
name
(str): Unique name for this prompt instancekey
(str): Unique key for the component instanceplaceholder
(str, optional): Placeholder text shown in input fielddefault
(Union[str, PromptReturn], optional): Default value for the prompt. Can include text and images using the PromptReturn
object type.main_bottom
(bool, optional): Pin prompt to bottom of main area (default: True)max_image_size
(int, optional): Maximum image size in bytes (default: 5MB)disabled
(bool, optional): Disable the prompt (default: False)Returns:
Optional[PromptReturn]
: Object containing message and images if submitted, None otherwise
Object returned when user submits the prompt.
Properties:
text
(Optional[str]): Text message entered by userimages
(Optional[List[ImageData]]): List of attached imagesObject representing an attached image.
Properties:
type
(str): Image MIME type (e.g. "image/jpeg")format
(str): Image format (e.g. "base64")data
(str): Image data as base64 stringThis repository is based on the Streamlit Component template system. If you want to modify or develop the component:
Clone the repository
Install development dependencies:
pip install -e ".[devel]"
Start the frontend development server:
cd streamlit_chat_prompt/frontend
npm install
npm run start
In a separate terminal, run your Streamlit app:
streamlit run your_app.py
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
FAQs
Streamlit component that allows you to create a chat prompt with paste and image attachment support
We found that streamlit-chat-prompt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.