ytrsoymr commited on
Commit
c62bab1
·
verified ·
1 Parent(s): 2aa9473

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -1,30 +1,33 @@
1
  import streamlit as st
2
  from chatbot.conversation import chat_bot
3
- from chatbot.database import get_chat_history, save_chat, get_chat_sessions
 
 
 
4
  from config import generate_session_id
5
 
6
- # User ID input
 
 
7
  st.title("DataScience-AI-Mentor")
8
  st.write("Your AI-powered Data Science Tutor. Ask me anything related to Data Science!")
9
 
10
- if "user_id" not in st.session_state:
11
- user_input_id = st.text_input("Enter your User ID (or leave blank to generate a new one):")
12
- if user_input_id:
13
- st.session_state.user_id = user_input_id
14
- else:
15
- from config import generate_user_id
16
- st.session_state.user_id = generate_user_id()
17
- st.write(f"Your new User ID: {st.session_state.user_id}")
18
-
19
- # Select or create a chat session
20
- session_options = get_chat_sessions(st.session_state.user_id) + ["Start New Chat"]
21
- st.session_state.session_id = st.selectbox("Select a chat session:", session_options)
22
-
23
- if st.session_state.session_id == "Start New Chat":
24
- st.session_state.session_id = generate_session_id()
25
 
26
  # Display chat history
27
- history = get_chat_history(st.session_state.user_id, st.session_state.session_id)
28
  for user_msg, bot_resp in history:
29
  with st.chat_message("user"):
30
  st.write(user_msg)
@@ -34,7 +37,7 @@ for user_msg, bot_resp in history:
34
  # User input
35
  user_input = st.chat_input("Type your message...")
36
  if user_input:
37
- response = chat_bot(user_input, st.session_state.session_id)
38
 
39
  # Display messages in chat
40
  with st.chat_message("user"):
@@ -43,4 +46,4 @@ if user_input:
43
  st.write(response)
44
 
45
  # Save chat history
46
- save_chat(st.session_state.user_id, st.session_state.session_id, user_input, response)
 
1
  import streamlit as st
2
  from chatbot.conversation import chat_bot
3
+ from chatbot.database import get_chat_history, save_chat
4
+
5
+
6
+ # Generate or retrieve session ID
7
  from config import generate_session_id
8
 
9
+ if "session_id" not in st.session_state:
10
+ st.session_state.session_id = generate_session_id()
11
+
12
  st.title("DataScience-AI-Mentor")
13
  st.write("Your AI-powered Data Science Tutor. Ask me anything related to Data Science!")
14
 
15
+ st.markdown("""
16
+ ### **How It Works**
17
+ 1. **Start a Conversation**
18
+ - Type any **data science-related** question in the chat box.
19
+ - Example: *"What is machine learning?"* or *"How do I use Pandas for data analysis?"*
20
+ 2. **Receive an AI-Powered Response**
21
+ - The chatbot will **analyze your question** and provide a clear, step-by-step explanation.
22
+ 3. **Memory-Based Learning**
23
+ - The chatbot **remembers past interactions** within the same session for **context-aware discussions**.
24
+ 4. **Chat History**
25
+ - You can review your past questions and answers in the chat window.
26
+
27
+ """)
 
 
28
 
29
  # Display chat history
30
+ history = get_chat_history(st.session_state.session_id)
31
  for user_msg, bot_resp in history:
32
  with st.chat_message("user"):
33
  st.write(user_msg)
 
37
  # User input
38
  user_input = st.chat_input("Type your message...")
39
  if user_input:
40
+ response, session_id = chat_bot(user_input, st.session_state.session_id)
41
 
42
  # Display messages in chat
43
  with st.chat_message("user"):
 
46
  st.write(response)
47
 
48
  # Save chat history
49
+ save_chat(session_id, user_input, response)