|
import streamlit as st |
|
from constitution_py import get_legal_response |
|
|
|
|
|
st.markdown("<h1 style='text-align: center; color: green;'>PakLegalAI</h1>", unsafe_allow_html=True) |
|
st.markdown("<hr>", unsafe_allow_html=True) |
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
for msg in st.session_state.messages: |
|
with st.chat_message(msg["role"]): |
|
st.markdown(msg["content"]) |
|
|
|
|
|
st.markdown( |
|
""" |
|
<script> |
|
const messages = window.parent.document.querySelector('div.stApp').querySelectorAll('.chat-message'); |
|
messages[messages.length - 1].scrollIntoView({ behavior: 'smooth' }); |
|
</script> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
user_input = st.chat_input("Ask a legal question about Pakistan's constitution...") |
|
|
|
if user_input: |
|
st.session_state.messages.append({"role": "user", "content": user_input}) |
|
with st.chat_message("user"): |
|
st.markdown(user_input) |
|
|
|
|
|
try: |
|
response = get_legal_response(user_input) |
|
except Exception as e: |
|
response = f"Sorry, I encountered an error: {str(e)}" |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": response}) |
|
with st.chat_message("assistant"): |
|
|
|
st.markdown(response) |
|
|