Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
#
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
)
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
|
|
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 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")
|