Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 7 |
-
|
| 8 |
-
st.session_state.user_id = st.text_input("Enter your User ID:", key="user_id_input")
|
| 9 |
|
| 10 |
-
if st.session_state
|
| 11 |
-
st.
|
| 12 |
-
st.write("Your AI-powered Data Science Tutor. Ask me anything related to Data Science!")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|