import streamlit as st
from constitution_py import get_legal_response # ✅ importing from constitution.py
# Title
st.markdown("
PakLegalAI
", unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
# Chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Show chat history
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
# Automatically scroll to bottom with custom JavaScript
st.markdown(
"""
""", unsafe_allow_html=True)
# Chat input
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)
# ✅ Real response from your logic
try:
response = get_legal_response(user_input)
response = '\n'.join([response['title'], response['article_number'], response['answer']])
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)