File size: 1,650 Bytes
104d989
 
c62bab1
 
 
 
9660ca1
104d989
c62bab1
 
 
9660ca1
 
104d989
c62bab1
 
 
 
 
 
 
 
 
 
 
 
 
f1ff20d
9660ca1
c62bab1
9660ca1
 
 
 
 
f1ff20d
9660ca1
 
 
c62bab1
9660ca1
 
 
 
 
 
 
 
c62bab1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import streamlit as st
from chatbot.conversation import chat_bot
from chatbot.database import get_chat_history, save_chat


# Generate or retrieve session ID
from config import generate_session_id

if "session_id" not in st.session_state:
    st.session_state.session_id = generate_session_id()

st.title("DataScience-AI-Mentor")
st.write("Your AI-powered Data Science Tutor. Ask me anything related to Data Science!")

st.markdown("""
### **How It Works**
1. **Start a Conversation**
   - Type any **data science-related** question in the chat box.
   - Example: *"What is machine learning?"* or *"How do I use Pandas for data analysis?"*
2. **Receive an AI-Powered Response**
   - The chatbot will **analyze your question** and provide a clear, step-by-step explanation.
3. **Memory-Based Learning**
   - The chatbot **remembers past interactions** within the same session for **context-aware discussions**.
4. **Chat History**
   - You can review your past questions and answers in the chat window.
  
""")

# Display chat history
history = get_chat_history(st.session_state.session_id)
for user_msg, bot_resp in history:
    with st.chat_message("user"):
        st.write(user_msg)
    with st.chat_message("assistant"):
        st.write(bot_resp)

# User input
user_input = st.chat_input("Type your message...")
if user_input:
    response, session_id = chat_bot(user_input, st.session_state.session_id)
    
    # Display messages in chat
    with st.chat_message("user"):
        st.write(user_input)
    with st.chat_message("assistant"):
        st.write(response)
    
    # Save chat history
    save_chat(session_id, user_input, response)