[new] streamlit deployment (#1034)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
OPENAI_API_KEY="sk-xxx"
|
||||
59
embedchain/deployment/streamlit.io/app.py
Normal file
59
embedchain/deployment/streamlit.io/app.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import streamlit as st
|
||||
|
||||
from embedchain import Pipeline as App
|
||||
|
||||
|
||||
@st.cache_resource
|
||||
def embedchain_bot():
|
||||
return App()
|
||||
|
||||
|
||||
st.title("💬 Chatbot")
|
||||
st.caption("🚀 An Embedchain app powered by OpenAI!")
|
||||
if "messages" not in st.session_state:
|
||||
st.session_state.messages = [
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": """
|
||||
Hi! I'm a chatbot. I can answer questions and learn new things!\n
|
||||
Ask me anything and if you want me to learn something do `/add <source>`.\n
|
||||
I can learn mostly everything. :)
|
||||
""",
|
||||
}
|
||||
]
|
||||
|
||||
for message in st.session_state.messages:
|
||||
with st.chat_message(message["role"]):
|
||||
st.markdown(message["content"])
|
||||
|
||||
if prompt := st.chat_input("Ask me anything!"):
|
||||
app = embedchain_bot()
|
||||
|
||||
if prompt.startswith("/add"):
|
||||
with st.chat_message("user"):
|
||||
st.markdown(prompt)
|
||||
st.session_state.messages.append({"role": "user", "content": prompt})
|
||||
prompt = prompt.replace("/add", "").strip()
|
||||
with st.chat_message("assistant"):
|
||||
message_placeholder = st.empty()
|
||||
message_placeholder.markdown("Adding to knowledge base...")
|
||||
app.add(prompt)
|
||||
message_placeholder.markdown(f"Added {prompt} to knowledge base!")
|
||||
st.session_state.messages.append({"role": "assistant", "content": f"Added {prompt} to knowledge base!"})
|
||||
st.stop()
|
||||
|
||||
with st.chat_message("user"):
|
||||
st.markdown(prompt)
|
||||
st.session_state.messages.append({"role": "user", "content": prompt})
|
||||
|
||||
with st.chat_message("assistant"):
|
||||
msg_placeholder = st.empty()
|
||||
msg_placeholder.markdown("Thinking...")
|
||||
full_response = ""
|
||||
|
||||
for response in app.chat(prompt):
|
||||
msg_placeholder.empty()
|
||||
full_response += response
|
||||
|
||||
msg_placeholder.markdown(full_response)
|
||||
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
||||
2
embedchain/deployment/streamlit.io/requirements.txt
Normal file
2
embedchain/deployment/streamlit.io/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
streamlit==1.29.0
|
||||
embedchain
|
||||
Reference in New Issue
Block a user