cryogenic22 commited on
Commit
13b4a25
Β·
verified Β·
1 Parent(s): aef9d03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -94
app.py CHANGED
@@ -4,6 +4,7 @@ from utils.document_processor import DocumentProcessor
4
  from utils.case_manager import CaseManager
5
  from utils.legal_notebook_interface import LegalNotebookInterface
6
  from utils.case_manager_interface import CaseManagerInterface
 
7
  from datetime import datetime
8
  import os
9
  from pathlib import Path
@@ -119,102 +120,71 @@ def main():
119
  # Initialize components
120
  case_manager, vector_store, doc_processor = init_components()
121
 
122
- # Sidebar navigation (clean and minimal)
123
- tab = st.sidebar.radio(
124
- "Navigation",
125
- ["πŸ“ Case Manager", "πŸ“„ Document Analysis", "πŸ€– Legal Assistant"]
126
- )
127
 
128
- if tab == "πŸ“ Case Manager":
129
- st.title("πŸ“ Case Management")
 
130
 
131
- # Case creation form
132
- with st.expander("βž• Create New Case", expanded=True):
133
- with st.form("create_case_form"):
134
- title = st.text_input("Case Title")
135
- description = st.text_area("Description", placeholder="Enter case details...")
136
- case_type = st.selectbox(
137
- "Case Type",
138
- ["Judgment", "Contract", "MOU", "Will", "Other"]
139
- )
140
- create_case = st.form_submit_button("Create Case")
141
-
142
- if create_case and title:
143
- try:
144
- case_id = case_manager.create_case(title, description, case_type)
145
- st.success(f"Case '{title}' created successfully!")
146
- except Exception as e:
147
- st.error(f"Error creating case: {str(e)}")
148
-
149
- # List cases
150
- st.subheader("πŸ“œ Cases")
151
- try:
152
- cases = case_manager.get_all_cases()
153
- if cases:
154
- for case in cases:
155
- with st.expander(f"πŸ“‚ {case['title']}", expanded=False):
156
- st.markdown(f"**Type:** {case['case_type']}")
157
- st.markdown(f"**Description:** {case['description']}")
158
- st.markdown(f"**Created:** {case['created_at']}")
159
-
160
- # List documents
161
- documents = case_manager.list_documents(case["id"])
162
- if documents:
163
- st.markdown("### Documents")
164
- for doc in documents:
165
- st.markdown(f"- πŸ“„ {doc['title']} (Added: {doc['added_at']})")
166
-
167
- # Document upload
168
- uploaded_file = st.file_uploader(
169
- "Upload Document",
170
- key=f"upload_{case['id']}"
171
- )
172
-
173
- if uploaded_file:
174
- with st.status("Processing document...", expanded=True) as status:
175
- try:
176
- # Process document
177
- text, chunks, metadata = doc_processor.process_and_tag_document(uploaded_file)
178
-
179
- # Add to vector store
180
- for chunk in chunks:
181
- vector_store.add_document(
182
- doc_id=metadata['doc_id'],
183
- text=chunk['text'],
184
- metadata={
185
- **metadata,
186
- 'chunk_index': chunk.get('chunk_id', 0),
187
- 'total_chunks': len(chunks)
188
- }
189
- )
190
-
191
- # Add to case
192
- doc_data = {
193
- "id": metadata['doc_id'],
194
- "title": uploaded_file.name,
195
- "text": text,
196
- "metadata": metadata,
197
- "chunks": chunks
198
- }
199
- case_manager.add_document(case["id"], doc_data)
200
-
201
- st.success(f"Document '{uploaded_file.name}' added successfully!")
202
-
203
- except Exception as e:
204
- st.error(f"Error processing document: {str(e)}")
205
- else:
206
- st.info("No cases yet. Create your first case using the form above.")
207
-
208
- except Exception as e:
209
- st.error(f"Error loading cases: {str(e)}")
210
-
211
- elif tab == "πŸ“„ Document Analysis":
212
- notebook = LegalNotebookInterface(case_manager, vector_store, doc_processor)
213
- notebook.render()
214
-
215
- elif tab == "πŸ€– Legal Assistant":
216
- notebook = LegalNotebookInterface(case_manager, vector_store, doc_processor)
217
- notebook.render()
218
 
219
  except Exception as e:
220
  st.error("An unexpected error occurred")
 
4
  from utils.case_manager import CaseManager
5
  from utils.legal_notebook_interface import LegalNotebookInterface
6
  from utils.case_manager_interface import CaseManagerInterface
7
+ from utils.admin_interface import AdminInterface
8
  from datetime import datetime
9
  import os
10
  from pathlib import Path
 
120
  # Initialize components
121
  case_manager, vector_store, doc_processor = init_components()
122
 
123
+ # Session state for user authentication
124
+ if 'user_authenticated' not in st.session_state:
125
+ st.session_state.user_authenticated = False
126
+ st.session_state.current_user = None
 
127
 
128
+ # Sidebar navigation with admin access
129
+ if st.session_state.user_authenticated:
130
+ is_admin = st.session_state.current_user == 'admin'
131
 
132
+ navigation_options = ["πŸ“ Case Manager", "πŸ“„ Document Analysis", "πŸ€– Legal Assistant"]
133
+ if is_admin:
134
+ navigation_options.append("βš™οΈ Admin")
135
+
136
+ tab = st.sidebar.radio("Navigation", navigation_options)
137
+
138
+ # Add logout button
139
+ if st.sidebar.button("Logout"):
140
+ st.session_state.user_authenticated = False
141
+ st.session_state.current_user = None
142
+ st.rerun()
143
+
144
+ if tab == "πŸ“ Case Manager":
145
+ case_manager_interface = CaseManagerInterface(case_manager, vector_store, doc_processor)
146
+ case_manager_interface.render()
147
+
148
+ elif tab == "πŸ“„ Document Analysis":
149
+ notebook = LegalNotebookInterface(case_manager, vector_store, doc_processor)
150
+ notebook.render()
151
+
152
+ elif tab == "πŸ€– Legal Assistant":
153
+ notebook = LegalNotebookInterface(case_manager, vector_store, doc_processor)
154
+ notebook.render()
155
+
156
+ elif tab == "βš™οΈ Admin" and is_admin:
157
+ admin_interface = AdminInterface(case_manager, vector_store, doc_processor)
158
+ admin_interface.render()
159
+
160
+ else:
161
+ # Login form
162
+ st.sidebar.title("Login")
163
+ with st.sidebar.form("login_form"):
164
+ username = st.text_input("Username")
165
+ password = st.text_input("Password", type="password")
166
+ submit = st.form_submit_button("Login")
167
+
168
+ if submit:
169
+ if username == "admin" and password == "demo":
170
+ st.session_state.user_authenticated = True
171
+ st.session_state.current_user = "admin"
172
+ st.rerun()
173
+ # Here you can add more user authentication logic
174
+ else:
175
+ st.error("Invalid credentials")
176
+
177
+ # Show welcome message for non-authenticated users
178
+ st.markdown("""
179
+ ## Welcome to SuoMoto.AI
180
+ Please login to access the legal analysis tools.
181
+
182
+ ### Available Features:
183
+ - πŸ“ Case Management
184
+ - πŸ“„ Document Analysis
185
+ - πŸ€– Legal Assistant
186
+ - βš™οΈ Admin Panel (for administrators)
187
+ """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
  except Exception as e:
190
  st.error("An unexpected error occurred")