Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
|
|
|
|
|
|
|
|
|
| 4 |
from config import generate_session_id
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
st.title("DataScience-AI-Mentor")
|
| 8 |
st.write("Your AI-powered Data Science Tutor. Ask me anything related to Data Science!")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 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.
|
| 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(
|
|
|
|
| 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)
|