Saim-11 commited on
Commit
2b2073c
·
verified ·
1 Parent(s): b2300d6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from constitution_py import get_legal_response # ✅ importing from constitution.py
3
+
4
+ # Title
5
+ st.markdown("<h1 style='text-align: center; color: green;'>PakLegalAI</h1>", unsafe_allow_html=True)
6
+ st.markdown("<hr>", unsafe_allow_html=True)
7
+
8
+ # Chat history
9
+ if "messages" not in st.session_state:
10
+ st.session_state.messages = []
11
+
12
+ # Show chat history
13
+ for msg in st.session_state.messages:
14
+ with st.chat_message(msg["role"]):
15
+ st.markdown(msg["content"])
16
+
17
+ # Automatically scroll to bottom with custom JavaScript
18
+ st.markdown(
19
+ """
20
+ <script>
21
+ const messages = window.parent.document.querySelector('div.stApp').querySelectorAll('.chat-message');
22
+ messages[messages.length - 1].scrollIntoView({ behavior: 'smooth' });
23
+ </script>
24
+ """, unsafe_allow_html=True)
25
+
26
+ # Chat input
27
+ user_input = st.chat_input("Ask a legal question about Pakistan's constitution...")
28
+
29
+ if user_input:
30
+ st.session_state.messages.append({"role": "user", "content": user_input})
31
+ with st.chat_message("user"):
32
+ st.markdown(user_input)
33
+
34
+ # ✅ Real response from your logic
35
+ try:
36
+ response = get_legal_response(user_input)
37
+ except Exception as e:
38
+ response = f"Sorry, I encountered an error: {str(e)}"
39
+
40
+ st.session_state.messages.append({"role": "assistant", "content": response})
41
+ with st.chat_message("assistant"):
42
+
43
+ st.markdown(response)