ytrsoymr commited on
Commit
9660ca1
Β·
verified Β·
1 Parent(s): b6565f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -24
app.py CHANGED
@@ -3,32 +3,56 @@ from chatbot.conversation import chat_bot
3
  from chatbot.database import get_chat_history, save_chat
4
 
5
 
6
- # Ask the user for a user ID
7
- if "user_id" not in st.session_state:
8
- st.session_state.user_id = st.text_input("Enter your User ID:", key="user_id_input")
9
 
10
- if st.session_state.user_id:
11
- st.title("DataScience-AI-Mentor")
12
- st.write("Your AI-powered Data Science Tutor. Ask me anything related to Data Science!")
13
 
14
- # Display chat history
15
- history = get_chat_history(st.session_state.user_id)
16
- for user_msg, bot_resp in history:
17
- with st.chat_message("user"):
18
- st.write(user_msg)
19
- with st.chat_message("assistant"):
20
- st.write(bot_resp)
21
 
22
- # User input
23
- user_input = st.chat_input("Type your message...")
24
- if user_input:
25
- response = chat_bot(user_input) # Get bot response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- # Display messages in chat
28
- with st.chat_message("user"):
29
- st.write(user_input)
30
- with st.chat_message("assistant"):
31
- st.write(response) # Do not include user_id
 
 
32
 
33
- # Save chat history
34
- save_chat(st.session_state.user_id, user_input, response)
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ### **Who Can Use It?**
27
+ - **Students & Beginners** β†’ Learn the basics of data science interactively.
28
+ - **Aspiring Data Scientists** β†’ Get help with coding, algorithms, and real-world applications.
29
+ - **Professionals & Researchers** β†’ Ask about advanced techniques and best practices.
30
+ - **Anyone Curious About Data Science** β†’ Explore AI, Machine Learning, SQL, Python, and more!
31
+ ### **Why Use DataScience-AI-Mentor?**
32
+ βœ… **User-Friendly Interface** – Just start chatting!
33
+ βœ… **Step-by-Step Explanations** – Learn in a structured way.
34
+ βœ… **Memory for Better Conversations** – Get answers based on previous messages.
35
+ βœ… **Saves Chat History** – Review past queries anytime.
36
+ """)
37
 
38
+ # Display chat history
39
+ history = get_chat_history(st.session_state.session_id)
40
+ for user_msg, bot_resp in history:
41
+ with st.chat_message("user"):
42
+ st.write(user_msg)
43
+ with st.chat_message("assistant"):
44
+ st.write(bot_resp)
45
 
46
+ # User input
47
+ user_input = st.chat_input("Type your message...")
48
+ if user_input:
49
+ response, session_id = chat_bot(user_input, st.session_state.session_id)
50
+
51
+ # Display messages in chat
52
+ with st.chat_message("user"):
53
+ st.write(user_input)
54
+ with st.chat_message("assistant"):
55
+ st.write(response)
56
+
57
+ # Save chat history
58
+ save_chat(session_id, user_input, response)