Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,14 +52,15 @@ if "session_id" not in st.session_state:
|
|
| 52 |
st.markdown("""
|
| 53 |
<style>
|
| 54 |
body {
|
| 55 |
-
background-color: #
|
| 56 |
}
|
| 57 |
.title-text {
|
| 58 |
text-align: center;
|
| 59 |
-
font-size:
|
| 60 |
font-weight: bold;
|
| 61 |
-
color: #
|
| 62 |
padding: 15px;
|
|
|
|
| 63 |
}
|
| 64 |
.stTextInput {
|
| 65 |
position: fixed;
|
|
@@ -67,21 +68,35 @@ st.markdown("""
|
|
| 67 |
width: 80%;
|
| 68 |
left: 10%;
|
| 69 |
z-index: 999;
|
|
|
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
.chat-container {
|
| 72 |
background-color: white;
|
| 73 |
padding: 20px;
|
| 74 |
-
border-radius:
|
| 75 |
-
box-shadow:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
</style>
|
| 78 |
""", unsafe_allow_html=True)
|
| 79 |
|
| 80 |
-
# Display title
|
| 81 |
-
st.markdown("""
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
# New Chat Button
|
| 84 |
-
|
|
|
|
| 85 |
st.session_state.session_id = str(uuid.uuid4()) # Generate new session
|
| 86 |
st.session_state.messages = [] # Clear chat history
|
| 87 |
st.rerun() # Refresh the app
|
|
@@ -117,7 +132,7 @@ chat = RunnableWithMessageHistory(
|
|
| 117 |
)
|
| 118 |
|
| 119 |
# Chat History Container
|
| 120 |
-
st.markdown("### Chat History")
|
| 121 |
chat_container = st.container()
|
| 122 |
|
| 123 |
# Load chat history and display it
|
|
@@ -127,10 +142,13 @@ if "messages" not in st.session_state:
|
|
| 127 |
with chat_container:
|
| 128 |
for role, content in st.session_state.messages:
|
| 129 |
with st.chat_message(role):
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
# User input at the bottom
|
| 133 |
-
user_input = st.text_input("Type your message here:", key="user_message")
|
| 134 |
|
| 135 |
# If user submits a message
|
| 136 |
if user_input:
|
|
@@ -144,10 +162,10 @@ if user_input:
|
|
| 144 |
save_message(session_id, "assistant", response)
|
| 145 |
st.session_state.messages.append(("assistant", response))
|
| 146 |
|
| 147 |
-
# Display AI response
|
| 148 |
with chat_container:
|
| 149 |
with st.chat_message("assistant"):
|
| 150 |
-
st.markdown(response)
|
| 151 |
|
| 152 |
# Clear the input field
|
| 153 |
st.session_state.pop("user_message")
|
|
|
|
| 52 |
st.markdown("""
|
| 53 |
<style>
|
| 54 |
body {
|
| 55 |
+
background-color: #F0F8FF;
|
| 56 |
}
|
| 57 |
.title-text {
|
| 58 |
text-align: center;
|
| 59 |
+
font-size: 32px;
|
| 60 |
font-weight: bold;
|
| 61 |
+
color: #1E88E5;
|
| 62 |
padding: 15px;
|
| 63 |
+
text-shadow: 2px 2px 5px rgba(0,0,0,0.2);
|
| 64 |
}
|
| 65 |
.stTextInput {
|
| 66 |
position: fixed;
|
|
|
|
| 68 |
width: 80%;
|
| 69 |
left: 10%;
|
| 70 |
z-index: 999;
|
| 71 |
+
border-radius: 20px;
|
| 72 |
+
padding: 10px;
|
| 73 |
+
border: 2px solid #1E88E5;
|
| 74 |
}
|
| 75 |
.chat-container {
|
| 76 |
background-color: white;
|
| 77 |
padding: 20px;
|
| 78 |
+
border-radius: 15px;
|
| 79 |
+
box-shadow: 3px 3px 12px rgba(0,0,0,0.2);
|
| 80 |
+
}
|
| 81 |
+
.user-message {
|
| 82 |
+
color: #00897B;
|
| 83 |
+
font-weight: bold;
|
| 84 |
+
}
|
| 85 |
+
.assistant-message {
|
| 86 |
+
color: #D81B60;
|
| 87 |
+
font-weight: bold;
|
| 88 |
}
|
| 89 |
</style>
|
| 90 |
""", unsafe_allow_html=True)
|
| 91 |
|
| 92 |
+
# Display title with animation
|
| 93 |
+
st.markdown("""
|
| 94 |
+
<h1 class='title-text'>β¨π¬ AI Data Science Tutor πβ¨</h1>
|
| 95 |
+
""", unsafe_allow_html=True)
|
| 96 |
|
| 97 |
+
# New Chat Button with emoji
|
| 98 |
+
theme_button = st.button("π Start a New Chat")
|
| 99 |
+
if theme_button:
|
| 100 |
st.session_state.session_id = str(uuid.uuid4()) # Generate new session
|
| 101 |
st.session_state.messages = [] # Clear chat history
|
| 102 |
st.rerun() # Refresh the app
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
# Chat History Container
|
| 135 |
+
st.markdown("### π Chat History")
|
| 136 |
chat_container = st.container()
|
| 137 |
|
| 138 |
# Load chat history and display it
|
|
|
|
| 142 |
with chat_container:
|
| 143 |
for role, content in st.session_state.messages:
|
| 144 |
with st.chat_message(role):
|
| 145 |
+
if role == "user":
|
| 146 |
+
st.markdown(f"<p class='user-message'>π€ {content}</p>", unsafe_allow_html=True)
|
| 147 |
+
else:
|
| 148 |
+
st.markdown(f"<p class='assistant-message'>π€ {content}</p>", unsafe_allow_html=True)
|
| 149 |
|
| 150 |
# User input at the bottom
|
| 151 |
+
user_input = st.text_input("π‘ Type your message here:", key="user_message")
|
| 152 |
|
| 153 |
# If user submits a message
|
| 154 |
if user_input:
|
|
|
|
| 162 |
save_message(session_id, "assistant", response)
|
| 163 |
st.session_state.messages.append(("assistant", response))
|
| 164 |
|
| 165 |
+
# Display AI response with animation
|
| 166 |
with chat_container:
|
| 167 |
with st.chat_message("assistant"):
|
| 168 |
+
st.markdown(f"<p class='assistant-message'>π€ {response}</p>", unsafe_allow_html=True)
|
| 169 |
|
| 170 |
# Clear the input field
|
| 171 |
st.session_state.pop("user_message")
|