AnnasBlackHat commited on
Commit
7c2bf62
·
2 Parent(s): 147eaac fc2e018

Merge branch 'dev'

Browse files
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
- # Create a placeholder for the chat history
6
- chat_history = st.empty()
 
 
 
 
 
 
 
 
 
 
7
 
8
- # Create a text input for the user's message
9
- user_message = st.text_input("Type your message here", "")
10
 
11
- # Simulate a response from the chatbot (replace this with your RAG model later)
12
- if user_message:
13
- response = f"Response: {user_message.upper()}"
14
 
15
- # Update the chat history placeholder
16
- chat_history.markdown(f"**User:** {user_message}\n\n**Bot:** {response}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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})