Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 372 |
|
| 373 |
-
with
|
| 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 |
-
|
| 400 |
-
|
| 401 |
-
|
| 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 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 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
|
| 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:
|