repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import os |
| #2 | |
| #3 | import streamlit as st |
| #4 | |
| #5 | from embedchain import App |
| #6 | |
| #7 | |
| #8 | @st.cache_resource |
| #9 | def ec_app(): |
| #10 | return App.from_config(config_path="config.yaml") |
| #11 | |
| #12 | |
| #13 | with st.sidebar: |
| #14 | huggingface_access_token = st.text_input("Hugging face Token", key="chatbot_api_key", type="password") |
| #15 | "[Get Hugging Face Access Token](https://huggingface.co/settings/tokens)" |
| #16 | "[View the source code](https://github.com/embedchain/examples/mistral-streamlit)" |
| #17 | |
| #18 | |
| #19 | st.title("💬 Chatbot") |
| #20 | st.caption("🚀 An Embedchain app powered by Mistral!") |
| #21 | if "messages" not in st.session_state: |
| #22 | st.session_state.messages = [ |
| #23 | { |
| #24 | "role": "assistant", |
| #25 | "content": """ |
| #26 | Hi! I'm a chatbot. I can answer questions and learn new things!\n |
| #27 | Ask me anything and if you want me to learn something do `/add <source>`.\n |
| #28 | I can learn mostly everything. :) |
| #29 | """, |
| #30 | } |
| #31 | ] |
| #32 | |
| #33 | for message in st.session_state.messages: |
| #34 | with st.chat_message(message["role"]): |
| #35 | st.markdown(message["content"]) |
| #36 | |
| #37 | if prompt := st.chat_input("Ask me anything!"): |
| #38 | if not st.session_state.chatbot_api_key: |
| #39 | st.error("Please enter your Hugging Face Access Token") |
| #40 | st.stop() |
| #41 | |
| #42 | os.environ["HUGGINGFACE_ACCESS_TOKEN"] = st.session_state.chatbot_api_key |
| #43 | app = ec_app() |
| #44 | |
| #45 | if prompt.startswith("/add"): |
| #46 | with st.chat_message("user"): |
| #47 | st.markdown(prompt) |
| #48 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| #49 | prompt = prompt.replace("/add", "").strip() |
| #50 | with st.chat_message("assistant"): |
| #51 | message_placeholder = st.empty() |
| #52 | message_placeholder.markdown("Adding to knowledge base...") |
| #53 | app.add(prompt) |
| #54 | message_placeholder.markdown(f"Added {prompt} to knowledge base!") |
| #55 | st.session_state.messages.append({"role": "assistant", "content": f"Added {prompt} to knowledge base!"}) |
| #56 | st.stop() |
| #57 | |
| #58 | with st.chat_message("user"): |
| #59 | st.markdown(prompt) |
| #60 | st.session_state.messages.append({"role": "user", "content": prompt}) |
| #61 | |
| #62 | with st.chat_message("assistant"): |
| #63 | msg_placeholder = st.empty() |
| #64 | msg_placeholder.markdown("Thinking...") |
| #65 | full_response = "" |
| #66 | |
| #67 | for response in app.chat(prompt): |
| #68 | msg_placeholder.empty() |
| #69 | full_response += response |
| #70 | |
| #71 | msg_placeholder.markdown(full_response) |
| #72 | st.session_state.messages.append({"role": "assistant", "content": full_response}) |
| #73 |