raymondEDS commited on
Commit
63720b6
Β·
1 Parent(s): fcc0aea

remove login

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -3
  2. src/streamlit_app.py +62 -168
requirements.txt CHANGED
@@ -1,7 +1,5 @@
1
  altair
2
  pandas
3
  streamlit
4
- streamlit-authenticator
5
  PyPDF2
6
- python-multipart
7
- bcrypt
 
1
  altair
2
  pandas
3
  streamlit
 
4
  PyPDF2
5
+ python-multipart
 
src/streamlit_app.py CHANGED
@@ -1,8 +1,4 @@
1
  import streamlit as st
2
- import streamlit_authenticator as stauth
3
- import yaml
4
- from yaml.loader import SafeLoader
5
- import os
6
  import PyPDF2
7
  import io
8
  import base64
@@ -18,54 +14,15 @@ st.set_page_config(
18
  )
19
 
20
  # Initialize session state
21
- if 'authenticated' not in st.session_state:
22
- st.session_state.authenticated = False
23
- if 'username' not in st.session_state:
24
- st.session_state.username = None
25
  if 'uploaded_documents' not in st.session_state:
26
  st.session_state.uploaded_documents = {}
27
- if 'users_config' not in st.session_state:
28
- st.session_state.users_config = None
29
 
30
- def create_default_users():
31
- """Create default users configuration"""
32
- # Hash passwords using the correct syntax
33
- hasher = stauth.Hasher()
34
- hashed_passwords = hasher.generate(['admin123', 'teacher123', 'student123'])
35
-
36
- default_users = {
37
- 'credentials': {
38
- 'usernames': {
39
- 'admin': {
40
- 'email': 'admin@example.com',
41
- 'name': 'Administrator',
42
- 'password': hashed_passwords[0]
43
- },
44
- 'teacher': {
45
- 'email': 'teacher@example.com',
46
- 'name': 'Teacher',
47
- 'password': hashed_passwords[1]
48
- },
49
- 'student': {
50
- 'email': 'student@example.com',
51
- 'name': 'Student',
52
- 'password': hashed_passwords[2]
53
- }
54
- }
55
- }
56
- }
57
- return default_users
58
-
59
- def load_users():
60
- """Load users configuration"""
61
- if st.session_state.users_config is None:
62
- st.session_state.users_config = create_default_users()
63
- return st.session_state.users_config
64
-
65
- def save_document_info(username, filename, file_content, file_type):
66
  """Save document information to session state"""
67
- if username not in st.session_state.uploaded_documents:
68
- st.session_state.uploaded_documents[username] = []
69
 
70
  document_info = {
71
  'filename': filename,
@@ -75,7 +32,7 @@ def save_document_info(username, filename, file_content, file_type):
75
  'content': file_content.decode('latin-1') if isinstance(file_content, bytes) else str(file_content)
76
  }
77
 
78
- st.session_state.uploaded_documents[username].append(document_info)
79
 
80
  def extract_pdf_text(pdf_file):
81
  """Extract text from PDF file"""
@@ -90,85 +47,28 @@ def extract_pdf_text(pdf_file):
90
  return ""
91
 
92
  def main():
93
- # Load users
94
- config = load_users()
95
-
96
- # Create authenticator
97
- authenticator = stauth.Authenticate(
98
- config['credentials'],
99
- 'dev_lms',
100
- 'auth_key',
101
- cookie_expiry_days=30
102
- )
103
-
104
  # Sidebar for navigation
105
  with st.sidebar:
106
  st.title("πŸ“š Dev LMS")
107
  st.markdown("---")
108
 
109
- if not st.session_state.authenticated:
110
- st.info("Please login to access the LMS")
111
- else:
112
- st.success(f"Welcome, {st.session_state.username}!")
113
- st.markdown("---")
114
-
115
- # Navigation
116
- page = st.selectbox(
117
- "Navigation",
118
- ["Dashboard", "Upload Documents", "My Documents", "Document Library", "Settings"]
119
- )
120
 
121
  # Main content area
122
- if not st.session_state.authenticated:
123
- # Login page
124
- st.title("πŸ” Login to Dev LMS")
125
- st.markdown("---")
126
-
127
- col1, col2, col3 = st.columns([1, 2, 1])
128
- with col2:
129
- name, authentication_status, username = authenticator.login('Login', 'main')
130
-
131
- if authentication_status == False:
132
- st.error('Username/password is incorrect')
133
- elif authentication_status == None:
134
- st.warning('Please enter your username and password')
135
- elif authentication_status:
136
- st.session_state.authenticated = True
137
- st.session_state.username = username
138
- st.success(f'Welcome {name}')
139
- st.rerun()
140
-
141
- # Show default credentials
142
- with st.expander("Default Login Credentials"):
143
- st.markdown("""
144
- **Default Users:**
145
- - **Admin**: username: `admin`, password: `admin123`
146
- - **Teacher**: username: `teacher`, password: `teacher123`
147
- - **Student**: username: `student`, password: `student123`
148
- """)
149
-
150
- else:
151
- # Authenticated user content
152
- if 'page' not in locals():
153
- page = "Dashboard"
154
-
155
- if page == "Dashboard":
156
- show_dashboard()
157
- elif page == "Upload Documents":
158
- show_upload_documents()
159
- elif page == "My Documents":
160
- show_my_documents()
161
- elif page == "Document Library":
162
- show_document_library()
163
- elif page == "Settings":
164
- show_settings()
165
-
166
- # Logout button
167
- st.sidebar.markdown("---")
168
- if st.sidebar.button("Logout"):
169
- st.session_state.authenticated = False
170
- st.session_state.username = None
171
- st.rerun()
172
 
173
  def show_dashboard():
174
  """Show the main dashboard"""
@@ -179,23 +79,22 @@ def show_dashboard():
179
 
180
  with col1:
181
  st.metric(
182
- label="My Documents",
183
- value=len(st.session_state.uploaded_documents.get(st.session_state.username, [])),
184
  delta="0"
185
  )
186
 
187
  with col2:
188
- total_docs = sum(len(docs) for docs in st.session_state.uploaded_documents.values())
189
  st.metric(
190
- label="Total Documents",
191
- value=total_docs,
192
  delta="0"
193
  )
194
 
195
  with col3:
196
  st.metric(
197
- label="Active Users",
198
- value=len(st.session_state.uploaded_documents.keys()),
199
  delta="0"
200
  )
201
 
@@ -203,8 +102,9 @@ def show_dashboard():
203
 
204
  # Recent activity
205
  st.subheader("πŸ“ˆ Recent Activity")
206
- if st.session_state.uploaded_documents.get(st.session_state.username):
207
- recent_docs = st.session_state.uploaded_documents[st.session_state.username][-5:]
 
208
  for doc in recent_docs:
209
  with st.container():
210
  col1, col2, col3 = st.columns([3, 2, 1])
@@ -215,6 +115,8 @@ def show_dashboard():
215
  with col3:
216
  st.write(f"{doc['file_type']}")
217
  st.markdown("---")
 
 
218
 
219
  def show_upload_documents():
220
  """Show document upload interface"""
@@ -251,7 +153,6 @@ def show_upload_documents():
251
  if st.button("Upload Document"):
252
  # Save document info
253
  save_document_info(
254
- st.session_state.username,
255
  uploaded_file.name,
256
  uploaded_file.read(),
257
  "PDF"
@@ -261,13 +162,13 @@ def show_upload_documents():
261
  st.balloons()
262
 
263
  def show_my_documents():
264
- """Show user's uploaded documents"""
265
  st.title("πŸ“ My Documents")
266
  st.markdown("---")
267
 
268
- user_docs = st.session_state.uploaded_documents.get(st.session_state.username, [])
269
 
270
- if not user_docs:
271
  st.info("You haven't uploaded any documents yet.")
272
  return
273
 
@@ -275,10 +176,10 @@ def show_my_documents():
275
  search_term = st.text_input("πŸ” Search documents", placeholder="Enter filename or content...")
276
 
277
  # Filter documents based on search
278
- filtered_docs = user_docs
279
  if search_term:
280
  filtered_docs = [
281
- doc for doc in user_docs
282
  if search_term.lower() in doc['filename'].lower() or
283
  search_term.lower() in doc.get('content', '').lower()
284
  ]
@@ -318,29 +219,22 @@ def show_document_library():
318
  st.title("πŸ“š Document Library")
319
  st.markdown("---")
320
 
321
- if not st.session_state.uploaded_documents:
 
 
322
  st.info("No documents have been uploaded to the system yet.")
323
  return
324
 
325
  # Search functionality
326
- search_term = st.text_input("πŸ” Search all documents", placeholder="Enter filename, content, or username...")
327
-
328
- # Collect all documents
329
- all_docs = []
330
- for username, docs in st.session_state.uploaded_documents.items():
331
- for doc in docs:
332
- doc_copy = doc.copy()
333
- doc_copy['owner'] = username
334
- all_docs.append(doc_copy)
335
 
336
  # Filter documents based on search
337
- filtered_docs = all_docs
338
  if search_term:
339
  filtered_docs = [
340
- doc for doc in all_docs
341
  if search_term.lower() in doc['filename'].lower() or
342
- search_term.lower() in doc.get('content', '').lower() or
343
- search_term.lower() in doc['owner'].lower()
344
  ]
345
 
346
  if not filtered_docs:
@@ -350,7 +244,7 @@ def show_document_library():
350
  # Display documents
351
  for i, doc in enumerate(filtered_docs):
352
  with st.container():
353
- col1, col2, col3, col4, col5 = st.columns([3, 2, 1, 1, 1])
354
 
355
  with col1:
356
  st.write(f"**{doc['filename']}**")
@@ -362,12 +256,8 @@ def show_document_library():
362
  st.write(f"{doc['file_type']}")
363
 
364
  with col4:
365
- st.write(f"By: {doc['owner']}")
366
-
367
- with col5:
368
  if st.button(f"View {i}", key=f"lib_view_{i}"):
369
  st.subheader(f"πŸ“„ {doc['filename']}")
370
- st.write(f"**Uploaded by:** {doc['owner']}")
371
  st.write(f"**Uploaded:** {doc['upload_time']}")
372
  st.write(f"**Size:** {doc['size']} bytes")
373
 
@@ -382,41 +272,45 @@ def show_settings():
382
  st.title("βš™οΈ Settings")
383
  st.markdown("---")
384
 
385
- st.subheader("πŸ‘€ User Information")
386
- st.write(f"**Username:** {st.session_state.username}")
387
- st.write(f"**Session ID:** {id(st.session_state)}")
388
-
389
- st.markdown("---")
390
-
391
  st.subheader("πŸ”§ System Information")
392
  st.write("**Version:** Dev LMS v1.0")
393
  st.write("**Features:**")
394
- st.write("- User authentication")
395
  st.write("- PDF document upload")
396
  st.write("- Document search and preview")
397
  st.write("- Document library")
 
398
 
399
  st.markdown("---")
400
 
401
  # Export data option
402
- if st.button("πŸ“₯ Export My Data"):
403
- user_docs = st.session_state.uploaded_documents.get(st.session_state.username, [])
404
- if user_docs:
405
  # Create JSON export
406
  export_data = {
407
- 'username': st.session_state.username,
408
  'export_date': datetime.now().isoformat(),
409
- 'documents': user_docs
410
  }
411
 
412
  st.download_button(
413
  label="Download JSON Export",
414
  data=json.dumps(export_data, indent=2),
415
- file_name=f"{st.session_state.username}_data_export.json",
416
  mime="application/json"
417
  )
418
  else:
419
  st.info("No data to export.")
 
 
 
 
 
 
 
 
 
 
 
420
 
421
  if __name__ == "__main__":
422
  main()
 
1
  import streamlit as st
 
 
 
 
2
  import PyPDF2
3
  import io
4
  import base64
 
14
  )
15
 
16
  # Initialize session state
 
 
 
 
17
  if 'uploaded_documents' not in st.session_state:
18
  st.session_state.uploaded_documents = {}
19
+ if 'current_user' not in st.session_state:
20
+ st.session_state.current_user = "User"
21
 
22
+ def save_document_info(filename, file_content, file_type):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  """Save document information to session state"""
24
+ if 'documents' not in st.session_state.uploaded_documents:
25
+ st.session_state.uploaded_documents['documents'] = []
26
 
27
  document_info = {
28
  'filename': filename,
 
32
  'content': file_content.decode('latin-1') if isinstance(file_content, bytes) else str(file_content)
33
  }
34
 
35
+ st.session_state.uploaded_documents['documents'].append(document_info)
36
 
37
  def extract_pdf_text(pdf_file):
38
  """Extract text from PDF file"""
 
47
  return ""
48
 
49
  def main():
 
 
 
 
 
 
 
 
 
 
 
50
  # Sidebar for navigation
51
  with st.sidebar:
52
  st.title("πŸ“š Dev LMS")
53
  st.markdown("---")
54
 
55
+ # Navigation
56
+ page = st.selectbox(
57
+ "Navigation",
58
+ ["Dashboard", "Upload Documents", "My Documents", "Document Library", "Settings"]
59
+ )
 
 
 
 
 
 
60
 
61
  # Main content area
62
+ if page == "Dashboard":
63
+ show_dashboard()
64
+ elif page == "Upload Documents":
65
+ show_upload_documents()
66
+ elif page == "My Documents":
67
+ show_my_documents()
68
+ elif page == "Document Library":
69
+ show_document_library()
70
+ elif page == "Settings":
71
+ show_settings()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  def show_dashboard():
74
  """Show the main dashboard"""
 
79
 
80
  with col1:
81
  st.metric(
82
+ label="Total Documents",
83
+ value=len(st.session_state.uploaded_documents.get('documents', [])),
84
  delta="0"
85
  )
86
 
87
  with col2:
 
88
  st.metric(
89
+ label="System Status",
90
+ value="Active",
91
  delta="0"
92
  )
93
 
94
  with col3:
95
  st.metric(
96
+ label="Storage Used",
97
+ value="Session",
98
  delta="0"
99
  )
100
 
 
102
 
103
  # Recent activity
104
  st.subheader("πŸ“ˆ Recent Activity")
105
+ documents = st.session_state.uploaded_documents.get('documents', [])
106
+ if documents:
107
+ recent_docs = documents[-5:]
108
  for doc in recent_docs:
109
  with st.container():
110
  col1, col2, col3 = st.columns([3, 2, 1])
 
115
  with col3:
116
  st.write(f"{doc['file_type']}")
117
  st.markdown("---")
118
+ else:
119
+ st.info("No documents uploaded yet. Start by uploading a PDF document!")
120
 
121
  def show_upload_documents():
122
  """Show document upload interface"""
 
153
  if st.button("Upload Document"):
154
  # Save document info
155
  save_document_info(
 
156
  uploaded_file.name,
157
  uploaded_file.read(),
158
  "PDF"
 
162
  st.balloons()
163
 
164
  def show_my_documents():
165
+ """Show uploaded documents"""
166
  st.title("πŸ“ My Documents")
167
  st.markdown("---")
168
 
169
+ documents = st.session_state.uploaded_documents.get('documents', [])
170
 
171
+ if not documents:
172
  st.info("You haven't uploaded any documents yet.")
173
  return
174
 
 
176
  search_term = st.text_input("πŸ” Search documents", placeholder="Enter filename or content...")
177
 
178
  # Filter documents based on search
179
+ filtered_docs = documents
180
  if search_term:
181
  filtered_docs = [
182
+ doc for doc in documents
183
  if search_term.lower() in doc['filename'].lower() or
184
  search_term.lower() in doc.get('content', '').lower()
185
  ]
 
219
  st.title("πŸ“š Document Library")
220
  st.markdown("---")
221
 
222
+ documents = st.session_state.uploaded_documents.get('documents', [])
223
+
224
+ if not documents:
225
  st.info("No documents have been uploaded to the system yet.")
226
  return
227
 
228
  # Search functionality
229
+ search_term = st.text_input("πŸ” Search all documents", placeholder="Enter filename or content...")
 
 
 
 
 
 
 
 
230
 
231
  # Filter documents based on search
232
+ filtered_docs = documents
233
  if search_term:
234
  filtered_docs = [
235
+ doc for doc in documents
236
  if search_term.lower() in doc['filename'].lower() or
237
+ search_term.lower() in doc.get('content', '').lower()
 
238
  ]
239
 
240
  if not filtered_docs:
 
244
  # Display documents
245
  for i, doc in enumerate(filtered_docs):
246
  with st.container():
247
+ col1, col2, col3, col4 = st.columns([3, 2, 1, 1])
248
 
249
  with col1:
250
  st.write(f"**{doc['filename']}**")
 
256
  st.write(f"{doc['file_type']}")
257
 
258
  with col4:
 
 
 
259
  if st.button(f"View {i}", key=f"lib_view_{i}"):
260
  st.subheader(f"πŸ“„ {doc['filename']}")
 
261
  st.write(f"**Uploaded:** {doc['upload_time']}")
262
  st.write(f"**Size:** {doc['size']} bytes")
263
 
 
272
  st.title("βš™οΈ Settings")
273
  st.markdown("---")
274
 
 
 
 
 
 
 
275
  st.subheader("πŸ”§ System Information")
276
  st.write("**Version:** Dev LMS v1.0")
277
  st.write("**Features:**")
 
278
  st.write("- PDF document upload")
279
  st.write("- Document search and preview")
280
  st.write("- Document library")
281
+ st.write("- Session-based storage")
282
 
283
  st.markdown("---")
284
 
285
  # Export data option
286
+ if st.button("πŸ“₯ Export All Data"):
287
+ documents = st.session_state.uploaded_documents.get('documents', [])
288
+ if documents:
289
  # Create JSON export
290
  export_data = {
 
291
  'export_date': datetime.now().isoformat(),
292
+ 'documents': documents
293
  }
294
 
295
  st.download_button(
296
  label="Download JSON Export",
297
  data=json.dumps(export_data, indent=2),
298
+ file_name=f"lms_data_export.json",
299
  mime="application/json"
300
  )
301
  else:
302
  st.info("No data to export.")
303
+
304
+ st.markdown("---")
305
+
306
+ # Clear data option
307
+ if st.button("πŸ—‘οΈ Clear All Data"):
308
+ if st.session_state.uploaded_documents.get('documents'):
309
+ st.session_state.uploaded_documents['documents'] = []
310
+ st.success("All documents have been cleared!")
311
+ st.rerun()
312
+ else:
313
+ st.info("No documents to clear.")
314
 
315
  if __name__ == "__main__":
316
  main()