MuhammadMubashir commited on
Commit
bc0779e
Β·
verified Β·
1 Parent(s): 5471594

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from PIL import Image
4
+
5
+ # Hugging Face Deployment Compatibility
6
+ st.set_page_config(page_title="Agentic RAG Legal Assistant", layout="wide")
7
+
8
+ # Load background and sidebar images
9
+ bg_image = "https://source.unsplash.com/1600x900/?law,court" # Background image
10
+ sidebar_image = "https://source.unsplash.com/400x600/?law,justice" # Sidebar image
11
+
12
+ # Custom CSS for background styling
13
+ st.markdown(
14
+ f"""
15
+ <style>
16
+ .stApp {{
17
+ background: url({bg_image}) no-repeat center center fixed;
18
+ background-size: cover;
19
+ }}
20
+ .sidebar .sidebar-content {{
21
+ background: url({sidebar_image}) no-repeat center center;
22
+ background-size: cover;
23
+ }}
24
+ </style>
25
+ """,
26
+ unsafe_allow_html=True,
27
+ )
28
+
29
+ # Sidebar Title
30
+ st.sidebar.title("βš–οΈ Legal AI Assistant")
31
+ st.sidebar.markdown("Your AI-powered legal research assistant.")
32
+
33
+ # Main Heading
34
+ st.markdown("# πŸ›οΈ Agentic RAG Legal Assistant")
35
+ st.markdown("### Your AI-powered assistant for legal research and case analysis.")
36
+
37
+ # Initialize conversation history
38
+ if "chat_history" not in st.session_state:
39
+ st.session_state.chat_history = []
40
+
41
+ # User input
42
+ user_query = st.text_input("πŸ” Enter your legal question:", "")
43
+
44
+ # FastAPI backend URL
45
+ API_URL = "http://127.0.0.1:8000/query/" # Change this to your deployed FastAPI URL
46
+
47
+ if st.button("Ask AI") and user_query:
48
+ with st.spinner("Fetching response..."):
49
+ try:
50
+ response = requests.post(API_URL, json={"query": user_query})
51
+ response_json = response.json()
52
+ ai_response = response_json.get("response", "Error: No response received.")
53
+ except Exception as e:
54
+ ai_response = f"Error: {e}"
55
+
56
+ # Update chat history
57
+ st.session_state.chat_history.append((user_query, ai_response))
58
+
59
+ # Display chat history
60
+ st.markdown("---")
61
+ st.markdown("### πŸ“œ Chat History")
62
+ for user_q, ai_r in st.session_state.chat_history:
63
+ st.markdown(f"**πŸ§‘β€βš–οΈ You:** {user_q}")
64
+ st.markdown(f"**πŸ€– AI:** {ai_r}")
65
+ st.markdown("---")
66
+
67
+ # Footer
68
+ st.markdown("---")
69
+ st.markdown("πŸš€ Powered by OpenAI, Pinecone, and LangChain.")