Annas Dev
commited on
Commit
·
fc2e018
1
Parent(s):
89f6f6b
simple gui chat, add base files
Browse files- app/usecases/chat_usecase.py +0 -0
- domain/usecases/faq_embedding.py +0 -0
- pages/chat.py +38 -10
app/usecases/chat_usecase.py
ADDED
|
File without changes
|
domain/usecases/faq_embedding.py
ADDED
|
File without changes
|
pages/chat.py
CHANGED
|
@@ -1,16 +1,44 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
st.title("Chat")
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
# Create a text input for the user's message
|
| 9 |
-
user_message = st.text_input("Type your message here", "")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
response = f"Response: {user_message.upper()}"
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
+
# Streamed response emulator
|
| 7 |
+
def response_generator():
|
| 8 |
+
response = random.choice(
|
| 9 |
+
[
|
| 10 |
+
"Hello there! How can I assist you today?",
|
| 11 |
+
"Hi, human! Is there anything I can help you with?",
|
| 12 |
+
"Do you need help?",
|
| 13 |
+
]
|
| 14 |
+
)
|
| 15 |
+
for word in response.split():
|
| 16 |
+
yield word + " "
|
| 17 |
+
time.sleep(0.05)
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
st.title("FAQ chat")
|
| 21 |
+
st.write('chat with our FAQ bot')
|
|
|
|
| 22 |
|
| 23 |
+
# Initialize chat history
|
| 24 |
+
if "messages" not in st.session_state:
|
| 25 |
+
st.session_state.messages = []
|
| 26 |
+
|
| 27 |
+
# Display chat messages from history on app rerun
|
| 28 |
+
for message in st.session_state.messages:
|
| 29 |
+
with st.chat_message(message["role"]):
|
| 30 |
+
st.markdown(message["content"])
|
| 31 |
+
|
| 32 |
+
# Accept user input
|
| 33 |
+
if prompt := st.chat_input("What is up?"):
|
| 34 |
+
# Add user message to chat history
|
| 35 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 36 |
+
# Display user message in chat message container
|
| 37 |
+
with st.chat_message("user"):
|
| 38 |
+
st.markdown(prompt)
|
| 39 |
+
|
| 40 |
+
# Display assistant response in chat message container
|
| 41 |
+
with st.chat_message("assistant"):
|
| 42 |
+
response = st.write_stream(response_generator())
|
| 43 |
+
# Add assistant response to chat history
|
| 44 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|