ShoaibAI commited on
Commit
0ecf6ae
Β·
verified Β·
1 Parent(s): b541e92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -36
app.py CHANGED
@@ -199,11 +199,6 @@ def load_tests():
199
  df = pd.read_sql_query("SELECT id, test_code, test_name, position FROM biochemical_tests ORDER BY position", conn)
200
  return df
201
 
202
- def load_species():
203
- conn = init_db()
204
- df = pd.read_sql_query("SELECT id, full_name, gram_stain FROM species ORDER BY full_name", conn)
205
- return df
206
-
207
  def identify_organism(reactions):
208
  conn = init_db()
209
 
@@ -312,6 +307,9 @@ st.markdown("""
312
  .stButton > button {
313
  width: 100%;
314
  }
 
 
 
315
  </style>
316
  """, unsafe_allow_html=True)
317
 
@@ -343,15 +341,11 @@ with st.sidebar:
343
  with col1:
344
  if st.button("🦠 E. coli", use_container_width=True):
345
  st.session_state['example'] = 'E. coli'
 
 
346
  with col2:
347
  if st.button("🧫 P. aeruginosa", use_container_width=True):
348
  st.session_state['example'] = 'P. aeruginosa'
349
-
350
- col3, col4 = st.columns(2)
351
- with col3:
352
- if st.button("🟑 S. aureus", use_container_width=True):
353
- st.session_state['example'] = 'S. aureus'
354
- with col4:
355
  if st.button("πŸ”„ Reset All", use_container_width=True):
356
  st.session_state['example'] = 'reset'
357
 
@@ -367,10 +361,10 @@ with st.sidebar:
367
  st.metric("Biochemical Tests", test_count)
368
  st.metric("Profile Entries", profile_count)
369
 
370
- # Main content
371
- col1, col2 = st.columns([2, 1])
372
 
373
- with col1:
374
  st.markdown("## 🧬 Biochemical Test Reactions")
375
  st.markdown("Select the reaction results for each test (20 positions)")
376
 
@@ -395,31 +389,30 @@ with col1:
395
  del st.session_state.example
396
  st.rerun()
397
 
398
- # Create grid of test buttons
399
- cols_per_row = 4
400
- for i in range(0, 20, cols_per_row):
401
- cols = st.columns(cols_per_row)
402
- for j in range(cols_per_row):
403
  idx = i + j
404
  if idx < 20:
405
  test = tests_df.iloc[idx]
406
  with cols[j]:
407
- with st.container():
408
- st.markdown(f"**{test['test_code']}**")
409
- st.caption(test['test_name'])
410
-
411
- # Reaction buttons
412
- col_a, col_b = st.columns(2)
413
- with col_a:
414
- button_type = "primary" if st.session_state.reactions[idx] == '+' else "secondary"
415
- if st.button(f"+", key=f"pos_{idx}", use_container_width=True, type=button_type):
416
- st.session_state.reactions[idx] = '+'
417
- st.rerun()
418
- with col_b:
419
- button_type = "primary" if st.session_state.reactions[idx] == '-' else "secondary"
420
- if st.button(f"-", key=f"neg_{idx}", use_container_width=True, type=button_type):
421
- st.session_state.reactions[idx] = '-'
422
- st.rerun()
423
 
424
  # Current profile display
425
  st.markdown("---")
@@ -432,7 +425,7 @@ with col1:
432
  results = identify_organism(st.session_state.reactions)
433
  st.session_state.results = results
434
 
435
- with col2:
436
  st.markdown("## 🎯 Identification Results")
437
 
438
  if 'results' in st.session_state and st.session_state.results:
 
199
  df = pd.read_sql_query("SELECT id, test_code, test_name, position FROM biochemical_tests ORDER BY position", conn)
200
  return df
201
 
 
 
 
 
 
202
  def identify_organism(reactions):
203
  conn = init_db()
204
 
 
307
  .stButton > button {
308
  width: 100%;
309
  }
310
+ div[data-testid="column"] {
311
+ padding: 0 5px;
312
+ }
313
  </style>
314
  """, unsafe_allow_html=True)
315
 
 
341
  with col1:
342
  if st.button("🦠 E. coli", use_container_width=True):
343
  st.session_state['example'] = 'E. coli'
344
+ if st.button("🟑 S. aureus", use_container_width=True):
345
+ st.session_state['example'] = 'S. aureus'
346
  with col2:
347
  if st.button("🧫 P. aeruginosa", use_container_width=True):
348
  st.session_state['example'] = 'P. aeruginosa'
 
 
 
 
 
 
349
  if st.button("πŸ”„ Reset All", use_container_width=True):
350
  st.session_state['example'] = 'reset'
351
 
 
361
  st.metric("Biochemical Tests", test_count)
362
  st.metric("Profile Entries", profile_count)
363
 
364
+ # Main content - Two columns for layout
365
+ left_col, right_col = st.columns([2, 1])
366
 
367
+ with left_col:
368
  st.markdown("## 🧬 Biochemical Test Reactions")
369
  st.markdown("Select the reaction results for each test (20 positions)")
370
 
 
389
  del st.session_state.example
390
  st.rerun()
391
 
392
+ # Create grid of test buttons - 4 columns
393
+ for i in range(0, 20, 4):
394
+ cols = st.columns(4)
395
+ for j in range(4):
 
396
  idx = i + j
397
  if idx < 20:
398
  test = tests_df.iloc[idx]
399
  with cols[j]:
400
+ st.markdown(f"**{test['test_code']}**")
401
+ st.caption(test['test_name'])
402
+
403
+ # Use radio buttons instead of nested columns to avoid nesting issues
404
+ reaction = st.radio(
405
+ "Reaction",
406
+ options=['-', '+'],
407
+ index=0 if st.session_state.reactions[idx] == '-' else 1,
408
+ key=f"test_{idx}",
409
+ label_visibility="collapsed",
410
+ horizontal=True
411
+ )
412
+
413
+ if reaction != st.session_state.reactions[idx]:
414
+ st.session_state.reactions[idx] = reaction
415
+ st.rerun()
416
 
417
  # Current profile display
418
  st.markdown("---")
 
425
  results = identify_organism(st.session_state.reactions)
426
  st.session_state.results = results
427
 
428
+ with right_col:
429
  st.markdown("## 🎯 Identification Results")
430
 
431
  if 'results' in st.session_state and st.session_state.results: