Upload app.py
Browse files
app.py
CHANGED
|
@@ -213,6 +213,30 @@ html, body, [class*="css"] {
|
|
| 213 |
color: var(--text) !important;
|
| 214 |
border-radius: 10px !important;
|
| 215 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
</style>
|
| 217 |
""", unsafe_allow_html=True)
|
| 218 |
|
|
@@ -446,57 +470,31 @@ st.markdown("""
|
|
| 446 |
""", unsafe_allow_html=True)
|
| 447 |
|
| 448 |
|
| 449 |
-
# ─── Chat Display ─────────────
|
| 450 |
-
chat_html = '<div class="chat-area" id="chatArea">'
|
| 451 |
-
|
| 452 |
if not st.session_state.messages:
|
| 453 |
-
|
| 454 |
<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;
|
| 455 |
-
height:
|
| 456 |
-
|
| 457 |
-
|
|
|
|
|
|
|
|
|
|
| 458 |
Ask any BSc Mathematics problem
|
| 459 |
</div>
|
| 460 |
<div style="font-size:0.82rem;color:#334155;margin-top:0.5rem;">
|
| 461 |
Calculus · Linear Algebra · Number Theory · ODEs · Real Analysis · and more
|
| 462 |
</div>
|
| 463 |
</div>
|
| 464 |
-
"""
|
| 465 |
else:
|
| 466 |
for msg in st.session_state.messages:
|
| 467 |
if msg["role"] == "user":
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
.replace("&", "&")
|
| 471 |
-
.replace("<", "<")
|
| 472 |
-
.replace(">", ">"))
|
| 473 |
-
chat_html += f'<div class="msg-user"><div class="bubble">🧑🎓 {safe}</div></div>'
|
| 474 |
else:
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
content = (content
|
| 478 |
-
.replace("&", "&")
|
| 479 |
-
.replace("<", "<")
|
| 480 |
-
.replace(">", ">"))
|
| 481 |
-
content = re.sub(r'\*\*(.*?)\*\*', r'<b>\1</b>', content)
|
| 482 |
-
content = content.replace('\n', '<br>')
|
| 483 |
-
chat_html += (
|
| 484 |
-
f'<div class="msg-ai">'
|
| 485 |
-
f'<div class="ai-avatar">∑</div>'
|
| 486 |
-
f'<div class="bubble">{content}</div>'
|
| 487 |
-
f'</div>'
|
| 488 |
-
)
|
| 489 |
-
|
| 490 |
-
chat_html += '</div>'
|
| 491 |
-
st.markdown(chat_html, unsafe_allow_html=True)
|
| 492 |
-
|
| 493 |
-
st.markdown("""
|
| 494 |
-
<script>
|
| 495 |
-
const c = document.getElementById('chatArea');
|
| 496 |
-
if (c) c.scrollTop = c.scrollHeight;
|
| 497 |
-
</script>
|
| 498 |
-
""", unsafe_allow_html=True)
|
| 499 |
-
|
| 500 |
|
| 501 |
# ─── Input Row ──────────────────────────────────────────────────────────────────
|
| 502 |
col1, col2 = st.columns([5, 1])
|
|
|
|
| 213 |
color: var(--text) !important;
|
| 214 |
border-radius: 10px !important;
|
| 215 |
}
|
| 216 |
+
|
| 217 |
+
/* ── st.chat_message styling ── */
|
| 218 |
+
[data-testid="stChatMessage"] {
|
| 219 |
+
background: #111d35 !important;
|
| 220 |
+
border: 1px solid #1e3058 !important;
|
| 221 |
+
border-radius: 12px !important;
|
| 222 |
+
padding: 0.8rem 1rem !important;
|
| 223 |
+
margin: 0.5rem 0 !important;
|
| 224 |
+
}
|
| 225 |
+
[data-testid="stChatMessageContent"] p {
|
| 226 |
+
color: #e2e8f0 !important;
|
| 227 |
+
font-family: 'Nunito', sans-serif !important;
|
| 228 |
+
font-size: 0.93rem !important;
|
| 229 |
+
line-height: 1.8 !important;
|
| 230 |
+
}
|
| 231 |
+
/* Make math blocks stand out */
|
| 232 |
+
.katex-display {
|
| 233 |
+
background: rgba(56,189,248,0.05) !important;
|
| 234 |
+
border-left: 3px solid #38bdf8 !important;
|
| 235 |
+
padding: 0.5rem 1rem !important;
|
| 236 |
+
border-radius: 0 8px 8px 0 !important;
|
| 237 |
+
margin: 0.5rem 0 !important;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
</style>
|
| 241 |
""", unsafe_allow_html=True)
|
| 242 |
|
|
|
|
| 470 |
""", unsafe_allow_html=True)
|
| 471 |
|
| 472 |
|
| 473 |
+
# ─── Chat Display (uses st.chat_message for proper LaTeX rendering) ─────────────
|
|
|
|
|
|
|
| 474 |
if not st.session_state.messages:
|
| 475 |
+
st.markdown("""
|
| 476 |
<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;
|
| 477 |
+
height:260px;text-align:center;
|
| 478 |
+
background:#0d1526;border:1px solid #1e3058;border-radius:14px;
|
| 479 |
+
margin-bottom:1rem;">
|
| 480 |
+
<div style="font-size:3rem;margin-bottom:0.8rem;">📐</div>
|
| 481 |
+
<div style="font-family:'Rajdhani',sans-serif;font-size:1.2rem;
|
| 482 |
+
color:#475569;letter-spacing:1px;">
|
| 483 |
Ask any BSc Mathematics problem
|
| 484 |
</div>
|
| 485 |
<div style="font-size:0.82rem;color:#334155;margin-top:0.5rem;">
|
| 486 |
Calculus · Linear Algebra · Number Theory · ODEs · Real Analysis · and more
|
| 487 |
</div>
|
| 488 |
</div>
|
| 489 |
+
""", unsafe_allow_html=True)
|
| 490 |
else:
|
| 491 |
for msg in st.session_state.messages:
|
| 492 |
if msg["role"] == "user":
|
| 493 |
+
with st.chat_message("user", avatar="🧑🎓"):
|
| 494 |
+
st.markdown(msg["content"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
else:
|
| 496 |
+
with st.chat_message("assistant", avatar="📐"):
|
| 497 |
+
st.markdown(msg["content"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
# ─── Input Row ──────────────────────────────────────────────────────────────────
|
| 500 |
col1, col2 = st.columns([5, 1])
|