[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KGG66MV8B7P923Q5HTP1SH":3,"skill-same:01M6KGG66MV8B7P923Q5HTP1SH":57},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":31,"linkOnly":32,"markdownContent":33,"markdownBody":34,"frontMatter":35,"refName":36,"commitSha":37,"skillDirectory":38,"forksCount":39,"repositoryHtmlUrl":40,"repositoryHomepageUrl":6,"ownerHtmlUrl":41,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":42,"install":43,"resources":56},"01M6KGG66MV8B7P923Q5HTP1SH","building-streamlit-chat-ui",null,"Building chat interfaces in Streamlit. Use when creating conversational UIs, chatbots, or AI assistants. Covers st.chat_message, st.chat_input, message history, and streaming responses.","legout\u002Fpi-config","legout","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1469563?v=4","01M6KGERP7E8TF4XARRKPFJ6HQ","Volker L.","01M6KGERT1FYD049PP1WW923TZ",3,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-chat-ui\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30],"ui","chat","streamlit","chat ui","building streamlit chat ui","streaming","history","use","message","input","chatbots","building chat interfaces","2026-11-10 10:12:30",false,"---\nname: building-streamlit-chat-ui\ndescription: Building chat interfaces in Streamlit. Use when creating conversational UIs, chatbots, or AI assistants. Covers st.chat_message, st.chat_input, message history, and streaming responses.\nlicense: Apache-2.0\n---\n\n# Streamlit chat interfaces\n\nBuild conversational UIs with Streamlit's chat elements.\n\n## Basic chat structure\n\n```python\nimport streamlit as st\n\nif \"messages\" not in st.session_state:\n    st.session_state.messages = []\n\n# Display chat history\nfor msg in st.session_state.messages:\n    with st.chat_message(msg[\"role\"]):\n        st.write(msg[\"content\"])\n\n# Handle new input\nif prompt := st.chat_input(\"Ask a question\"):\n    st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n\n    with st.chat_message(\"user\"):\n        st.write(prompt)\n\n    with st.chat_message(\"assistant\"):\n        response = get_response(prompt)  # Your LLM call\n        st.write(response)\n\n    st.session_state.messages.append({\"role\": \"assistant\", \"content\": response})\n```\n\n## Streaming responses\n\nUse `st.write_stream` for token-by-token display. Pass any generator that yields strings, including the OpenAI generator directly:\n\n```python\ndef get_streaming_response(prompt):\n    # Replace with your LLM client (OpenAI, Anthropic, Cortex, etc.)\n    for chunk in your_llm_client.stream(prompt):\n        yield chunk\n\nwith st.chat_message(\"assistant\"):\n    response = st.write_stream(get_streaming_response(prompt))\n\nst.session_state.messages.append({\"role\": \"assistant\", \"content\": response})\n```\n\nWith OpenAI, you can pass the stream directly:\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\nwith st.chat_message(\"assistant\"):\n    stream = client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=st.session_state.messages,\n        stream=True,\n    )\n    response = st.write_stream(stream)\n```\n\n## Chat message avatars\n\nStreamlit provides default avatars for \"user\" and \"assistant\" roles—only customize if you have a specific need. You can use icons or images:\n\n```python\n# With icons\nwith st.chat_message(\"assistant\", avatar=\":material\u002Frobot:\"):\n    st.write(assistant_message)\n\n# With images\nwith st.chat_message(\"user\", avatar=\"https:\u002F\u002Fexample.com\u002Favatar.png\"):\n    st.write(user_message)\n```\n\n## Suggestion chips\n\nOffer clickable suggestions before the first message. The pills disappear once the user sends a message, creating a clean onboarding experience:\n\n```python\nSUGGESTIONS = {\n    \":blue[:material\u002Fhelp:] What is Streamlit?\": \"Explain what Streamlit is\",\n    \":green[:material\u002Fcode:] Show me an example\": \"Show a simple Streamlit example\",\n}\n\n# Only show before first message - they disappear after\nif not st.session_state.messages:\n    selected = st.pills(\"Try asking:\", list(SUGGESTIONS.keys()), label_visibility=\"collapsed\")\n    if selected:\n        # Use the selection as the first prompt\n        prompt = SUGGESTIONS[selected]\n        st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n        st.rerun()\n```\n\nThe `if not st.session_state.messages` check ensures the suggestions only appear on an empty chat. Once a message is added, the pills vanish and the conversation takes over.\n\n## File uploads\n\nEnable file attachments with `accept_file`. When enabled, `st.chat_input` returns a dict-like object with `text` and `files` attributes:\n\n```python\nprompt = st.chat_input(\n    \"Ask about an image\",\n    accept_file=True,\n    file_type=[\"jpg\", \"jpeg\", \"png\"],\n)\n\nif prompt:\n    with st.chat_message(\"user\"):\n        if prompt.text:\n            st.write(prompt.text)\n        if prompt.files:\n            st.image(prompt.files[0])\n\n    # Send to vision model\n    with st.chat_message(\"assistant\"):\n        response = analyze_image(prompt.files[0], prompt.text)\n        st.write(response)\n```\n\nUse `accept_file=\"multiple\"` to allow multiple files.\n\n## Audio input\n\nEnable voice recording with `accept_audio`. The recorded audio is available as a WAV file:\n\n```python\nprompt = st.chat_input(\"Say something\", accept_audio=True)\n\nif prompt:\n    if prompt.audio:\n        st.audio(prompt.audio)\n    if prompt.text:\n        st.write(prompt.text)\n```\n\n### Dictation with speech-to-text\n\nConvert audio to text and inject it back into the chat input:\n\n```python\nprompt = st.chat_input(\"Say something\", accept_audio=True, key=\"chat\")\n\nif prompt and prompt.audio:\n    # Transcribe with Whisper or another STT model\n    transcript = openai.audio.transcriptions.create(\n        model=\"whisper-1\",\n        file=prompt.audio,\n    )\n    # Set the transcribed text as the next input\n    st.session_state.chat = transcript.text\n    st.rerun()\n```\n\n## User feedback\n\nAdd thumbs up\u002Fdown feedback to assistant messages. Also supports `\"stars\"` and `\"faces\"` ratings:\n\n```python\nwith st.chat_message(\"assistant\"):\n    st.markdown(response)\n    feedback = st.feedback(\"thumbs\")\n    if feedback is not None:\n        st.toast(f\"Feedback received: {'?' if feedback == 1 else '?'}\")\n```\n\n## Clear chat\n\nAdd a button to reset the conversation:\n\n```python\ndef clear_chat():\n    st.session_state.messages = []\n\nst.button(\"Clear chat\", on_click=clear_chat)\n```\n\n## Related skills\n\n- `connecting-streamlit-to-snowflake`: Database queries and Cortex chat example\n- `optimizing-streamlit-performance`: Caching strategies for LLM calls\n\n## References\n\n- [st.chat_message](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fchat\u002Fst.chat_message)\n- [st.chat_input](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fchat\u002Fst.chat_input)\n- [st.write_stream](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fwrite-magic\u002Fst.write_stream)\n","# Streamlit chat interfaces\n\nBuild conversational UIs with Streamlit's chat elements.\n\n## Basic chat structure\n\n```python\nimport streamlit as st\n\nif \"messages\" not in st.session_state:\n    st.session_state.messages = []\n\n# Display chat history\nfor msg in st.session_state.messages:\n    with st.chat_message(msg[\"role\"]):\n        st.write(msg[\"content\"])\n\n# Handle new input\nif prompt := st.chat_input(\"Ask a question\"):\n    st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n\n    with st.chat_message(\"user\"):\n        st.write(prompt)\n\n    with st.chat_message(\"assistant\"):\n        response = get_response(prompt)  # Your LLM call\n        st.write(response)\n\n    st.session_state.messages.append({\"role\": \"assistant\", \"content\": response})\n```\n\n## Streaming responses\n\nUse `st.write_stream` for token-by-token display. Pass any generator that yields strings, including the OpenAI generator directly:\n\n```python\ndef get_streaming_response(prompt):\n    # Replace with your LLM client (OpenAI, Anthropic, Cortex, etc.)\n    for chunk in your_llm_client.stream(prompt):\n        yield chunk\n\nwith st.chat_message(\"assistant\"):\n    response = st.write_stream(get_streaming_response(prompt))\n\nst.session_state.messages.append({\"role\": \"assistant\", \"content\": response})\n```\n\nWith OpenAI, you can pass the stream directly:\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\nwith st.chat_message(\"assistant\"):\n    stream = client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=st.session_state.messages,\n        stream=True,\n    )\n    response = st.write_stream(stream)\n```\n\n## Chat message avatars\n\nStreamlit provides default avatars for \"user\" and \"assistant\" roles—only customize if you have a specific need. You can use icons or images:\n\n```python\n# With icons\nwith st.chat_message(\"assistant\", avatar=\":material\u002Frobot:\"):\n    st.write(assistant_message)\n\n# With images\nwith st.chat_message(\"user\", avatar=\"https:\u002F\u002Fexample.com\u002Favatar.png\"):\n    st.write(user_message)\n```\n\n## Suggestion chips\n\nOffer clickable suggestions before the first message. The pills disappear once the user sends a message, creating a clean onboarding experience:\n\n```python\nSUGGESTIONS = {\n    \":blue[:material\u002Fhelp:] What is Streamlit?\": \"Explain what Streamlit is\",\n    \":green[:material\u002Fcode:] Show me an example\": \"Show a simple Streamlit example\",\n}\n\n# Only show before first message - they disappear after\nif not st.session_state.messages:\n    selected = st.pills(\"Try asking:\", list(SUGGESTIONS.keys()), label_visibility=\"collapsed\")\n    if selected:\n        # Use the selection as the first prompt\n        prompt = SUGGESTIONS[selected]\n        st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n        st.rerun()\n```\n\nThe `if not st.session_state.messages` check ensures the suggestions only appear on an empty chat. Once a message is added, the pills vanish and the conversation takes over.\n\n## File uploads\n\nEnable file attachments with `accept_file`. When enabled, `st.chat_input` returns a dict-like object with `text` and `files` attributes:\n\n```python\nprompt = st.chat_input(\n    \"Ask about an image\",\n    accept_file=True,\n    file_type=[\"jpg\", \"jpeg\", \"png\"],\n)\n\nif prompt:\n    with st.chat_message(\"user\"):\n        if prompt.text:\n            st.write(prompt.text)\n        if prompt.files:\n            st.image(prompt.files[0])\n\n    # Send to vision model\n    with st.chat_message(\"assistant\"):\n        response = analyze_image(prompt.files[0], prompt.text)\n        st.write(response)\n```\n\nUse `accept_file=\"multiple\"` to allow multiple files.\n\n## Audio input\n\nEnable voice recording with `accept_audio`. The recorded audio is available as a WAV file:\n\n```python\nprompt = st.chat_input(\"Say something\", accept_audio=True)\n\nif prompt:\n    if prompt.audio:\n        st.audio(prompt.audio)\n    if prompt.text:\n        st.write(prompt.text)\n```\n\n### Dictation with speech-to-text\n\nConvert audio to text and inject it back into the chat input:\n\n```python\nprompt = st.chat_input(\"Say something\", accept_audio=True, key=\"chat\")\n\nif prompt and prompt.audio:\n    # Transcribe with Whisper or another STT model\n    transcript = openai.audio.transcriptions.create(\n        model=\"whisper-1\",\n        file=prompt.audio,\n    )\n    # Set the transcribed text as the next input\n    st.session_state.chat = transcript.text\n    st.rerun()\n```\n\n## User feedback\n\nAdd thumbs up\u002Fdown feedback to assistant messages. Also supports `\"stars\"` and `\"faces\"` ratings:\n\n```python\nwith st.chat_message(\"assistant\"):\n    st.markdown(response)\n    feedback = st.feedback(\"thumbs\")\n    if feedback is not None:\n        st.toast(f\"Feedback received: {'?' if feedback == 1 else '?'}\")\n```\n\n## Clear chat\n\nAdd a button to reset the conversation:\n\n```python\ndef clear_chat():\n    st.session_state.messages = []\n\nst.button(\"Clear chat\", on_click=clear_chat)\n```\n\n## Related skills\n\n- `connecting-streamlit-to-snowflake`: Database queries and Cortex chat example\n- `optimizing-streamlit-performance`: Caching strategies for LLM calls\n\n## References\n\n- [st.chat_message](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fchat\u002Fst.chat_message)\n- [st.chat_input](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fchat\u002Fst.chat_input)\n- [st.write_stream](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fwrite-magic\u002Fst.write_stream)\n",{"name":5,"license":15,"description":7},"main","3efae68c898153694a2f4aad309c7ff9847b5602","installed-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-chat-ui",0,"https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config","https:\u002F\u002Fgithub.com\u002Flegout","2026-04-28 16:32:33",{"source":8,"skillName":5,"commands":44,"prompt":54,"zipAvailable":55},[45,48,51],{"tool":46,"command":47},"npx","npx skills add legout\u002Fpi-config --skill building-streamlit-chat-ui",{"tool":49,"command":50},"bunx","bunx skills add legout\u002Fpi-config --skill building-streamlit-chat-ui",{"tool":52,"command":53},"pnpm","pnpm dlx skills add legout\u002Fpi-config --skill building-streamlit-chat-ui","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-chat-ui\u002FSKILL.md",true,[],[58,95,123,138,156,177],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":62,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":75,"publishedAt":31},"01M6KGW7MYKZ8MWFKN1V8ZJ2EG","visual-explainer","Generate beautiful, self-contained HTML pages that visually explain systems, code changes, plans, and data. Use when the user asks for a diagram, architecture overview, diff review, plan review, project recap, comparison table, or any visual explanation of technical concepts. Also use proactively when you are about to render a complex ASCII table (4+ rows or 3+ columns) — present it as a styled HTML page instead.","MIT","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Fskills\u002Fvisual-explainer\u002FSKILL.md",[65,70],{"categoryNo":66,"categoryName":67,"taxonomyType":68,"taxonomyTypeDesc":69},"01JBSEEDCAT000000000000009","前端开发","SCENARIO","使用场景",{"categoryNo":71,"categoryName":72,"taxonomyType":73,"taxonomyTypeDesc":74},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[76,77,78,79,80,81,82,83,84,26,85,86,87,88,89,90,91,92,93,94],"visual explainer","explainer","visual","image","architecture","generate","plan","table","view","files","project","present","as","ascii table","ascii","you","concepts","surf","for",{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":62,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":107,"publishedAt":31},"01M6KGTMTJR6RXXC8AF29MQQW5","table-extractor",">","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Ftable-extractor\u002FSKILL.md",[101,104],{"categoryNo":102,"categoryName":103,"taxonomyType":68,"taxonomyTypeDesc":69},"01JBSEEDCAT000000000000002","文档处理",{"categoryNo":105,"categoryName":106,"taxonomyType":68,"taxonomyTypeDesc":69},"01JBSEEDCAT000000000000023","Skill与智能体开发",[83,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122],"table extractor","PDF","MCP","gpt","extraction","office","data","parsing","extract","en","zh","camelot","sonnet","opus","tables",{"skillNo":124,"name":125,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":62,"licenseFileUrl":6,"sourceHtmlUrl":126,"categories":127,"keywords":130,"publishedAt":31},"01M6KGSWF2R22Z63PAY5NT6GRY","smart-ocr","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fsmart-ocr\u002FSKILL.md",[128,129],{"categoryNo":102,"categoryName":103,"taxonomyType":68,"taxonomyTypeDesc":69},{"categoryNo":105,"categoryName":106,"taxonomyType":68,"taxonomyTypeDesc":69},[131,132,109,110,133,111,112,113,115,134,116,117,118,135,136,120,121,137],"ocr","smart ocr","support","text","multilingual","processing","paddleocr",{"skillNo":139,"name":140,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":62,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":148,"publishedAt":31},"01M6KGMKKFNC1PRNX2W3E243DR","html-slides","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fhtml-slides\u002FSKILL.md",[143,146,147],{"categoryNo":144,"categoryName":145,"taxonomyType":68,"taxonomyTypeDesc":69},"01JBSEEDCAT000000000000003","演示文稿",{"categoryNo":66,"categoryName":67,"taxonomyType":68,"taxonomyTypeDesc":69},{"categoryNo":105,"categoryName":106,"taxonomyType":68,"taxonomyTypeDesc":69},[149,150,151,152,110,153,111,113,117,118,154,155,120,121],"slides","html","html slides","pptx","web","revealjs","presentation",{"skillNo":157,"name":158,"nameZh":6,"description":159,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":160,"categories":161,"keywords":162,"publishedAt":31},"01M6KGJGVM0TWW632Y6VQQV2WN","using-streamlit-session-state","Using st.session_state to manage state across Streamlit reruns. Use when persisting data, handling widget state, implementing callbacks, or debugging state issues. Covers initialization patterns, widget-state association, and common gotchas.","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fusing-streamlit-session-state\u002FSKILL.md",[],[163,164,21,165,166,167,168,114,169,26,170,171,172,173,174,175,176],"state","session","session state","using streamlit session state","debugging","issues","common","manage","patterns","across","widget","Callbacks","implementing","initialization",{"skillNo":178,"name":179,"nameZh":6,"description":180,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":181,"categories":182,"keywords":184,"publishedAt":31},"01M6KGJD12GJB7W0ZG66JK00F6","using-streamlit-markdown","Covers all Markdown features in Streamlit including GitHub-flavored syntax plus Streamlit extensions like colored text, badges, Material icons, and LaTeX. Use when formatting text, labels, tooltips, or any text-rendering element.","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fusing-streamlit-markdown\u002FSKILL.md",[183],{"categoryNo":102,"categoryName":103,"taxonomyType":68,"taxonomyTypeDesc":69},[185,21,186,187,188,189,134,190,26,191,192,193,194,195,196,197],"markdown","using streamlit markdown","github","icons","LaTeX","syntax","formatting","element","material","rendering","extensions","features","labels"]