3g3ueiw
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="USMLE-style Medical Cases Demo")
|
| 5 |
+
st.title("USMLE-style Medical Cases Demo")
|
| 6 |
+
|
| 7 |
+
# Initialize session state for step tracking
|
| 8 |
+
if "step_case1" not in st.session_state:
|
| 9 |
+
st.session_state.step_case1 = 0
|
| 10 |
+
if "step_case2" not in st.session_state:
|
| 11 |
+
st.session_state.step_case2 = 0
|
| 12 |
+
|
| 13 |
+
tab1, tab2 = st.tabs(["Case 1: ALS Patient", "Case 2: Congenital Mutism"])
|
| 14 |
+
|
| 15 |
+
########################
|
| 16 |
+
# Case 1: ALS Patient
|
| 17 |
+
########################
|
| 18 |
+
with tab1:
|
| 19 |
+
img_display = st.empty()
|
| 20 |
+
|
| 21 |
+
# Step 0: initial image and case
|
| 22 |
+
if st.session_state.step_case1 == 0:
|
| 23 |
+
img1 = Image.open("1.png")
|
| 24 |
+
img_display.image(img1, caption="Patient MRI", use_column_width=True)
|
| 25 |
+
st.markdown("""
|
| 26 |
+
**Case:**
|
| 27 |
+
A 57-year-old male presents with progressive weakness in his right hand over the past 6 months. He reports muscle cramps and twitching in his arms and legs.
|
| 28 |
+
Over the past 2 months, he has noticed **slurred speech and difficulty projecting his voice**, making it harder to be understood. He also reports occasional choking when drinking liquids.
|
| 29 |
+
Past medical history is unremarkable. Examination shows fasciculations, hyperreflexia, and mild dysarthria. EMG shows denervation. MRI is unremarkable.
|
| 30 |
+
Diagnosis: **Amyotrophic Lateral Sclerosis (ALS)** with early bulbar involvement.
|
| 31 |
+
""")
|
| 32 |
+
if st.button("Next: Segment"):
|
| 33 |
+
st.session_state.step_case1 += 1
|
| 34 |
+
|
| 35 |
+
# Step 1: Segment
|
| 36 |
+
elif st.session_state.step_case1 == 1:
|
| 37 |
+
img2 = Image.open("2.png")
|
| 38 |
+
img_display.image(img2, caption="Segmented MRI", use_column_width=True)
|
| 39 |
+
if st.button("Next: Extract Vocal Tract"):
|
| 40 |
+
st.session_state.step_case1 += 1
|
| 41 |
+
|
| 42 |
+
# Step 2: Extract Vocal Tract
|
| 43 |
+
elif st.session_state.step_case1 == 2:
|
| 44 |
+
img3 = Image.open("3.png")
|
| 45 |
+
img_display.image(img3, caption="Vocal Tract Extraction", use_column_width=True)
|
| 46 |
+
if st.button("Next: Classify"):
|
| 47 |
+
st.session_state.step_case1 += 1
|
| 48 |
+
|
| 49 |
+
# Step 3: Classify
|
| 50 |
+
elif st.session_state.step_case1 == 3:
|
| 51 |
+
img4 = Image.open("4.png")
|
| 52 |
+
img_display.image(img4, caption="Classification Result", use_column_width=True)
|
| 53 |
+
if st.button("Next: Predict Audio"):
|
| 54 |
+
st.session_state.step_case1 += 1
|
| 55 |
+
|
| 56 |
+
# Step 4: Predict Audio
|
| 57 |
+
elif st.session_state.step_case1 == 4:
|
| 58 |
+
st.audio("1.wav", format="audio/wav")
|
| 59 |
+
if st.button("Next: Display Score"):
|
| 60 |
+
st.session_state.step_case1 += 1
|
| 61 |
+
|
| 62 |
+
# Step 5: Display Score
|
| 63 |
+
elif st.session_state.step_case1 == 5:
|
| 64 |
+
st.success("Score: 0.940 / 1.0")
|
| 65 |
+
|
| 66 |
+
########################
|
| 67 |
+
# Case 2: Congenital Mutism
|
| 68 |
+
########################
|
| 69 |
+
with tab2:
|
| 70 |
+
img_display2 = st.empty()
|
| 71 |
+
|
| 72 |
+
# Step 0: initial image and case
|
| 73 |
+
if st.session_state.step_case2 == 0:
|
| 74 |
+
img5 = Image.open("5.png")
|
| 75 |
+
img_display2.image(img5, caption="Patient MRI", use_column_width=True)
|
| 76 |
+
st.markdown("""
|
| 77 |
+
**Case:**
|
| 78 |
+
A 23-year-old male was born with congenital mutism and has never spoken. He now seeks to **restore his voice** using speech synthesis and vocal tract reconstruction.
|
| 79 |
+
The patient has normal cognition and hearing. Physical exam shows no structural abnormalities. Imaging studies (shown above) guide personalized speech restoration.
|
| 80 |
+
""")
|
| 81 |
+
if st.button("Next: Segment Case 2"):
|
| 82 |
+
st.session_state.step_case2 += 1
|
| 83 |
+
|
| 84 |
+
# Step 1: Segment
|
| 85 |
+
elif st.session_state.step_case2 == 1:
|
| 86 |
+
img6 = Image.open("6.png")
|
| 87 |
+
img_display2.image(img6, caption="Segmented MRI", use_column_width=True)
|
| 88 |
+
if st.button("Next: Extract Vocal Tract"):
|
| 89 |
+
st.session_state.step_case2 += 1
|
| 90 |
+
|
| 91 |
+
# Step 2: Extract Vocal Tract
|
| 92 |
+
elif st.session_state.step_case2 == 2:
|
| 93 |
+
img7 = Image.open("7.png")
|
| 94 |
+
img_display2.image(img7, caption="Vocal Tract Extraction", use_column_width=True)
|
| 95 |
+
if st.button("Next: Classify"):
|
| 96 |
+
st.session_state.step_case2 += 1
|
| 97 |
+
|
| 98 |
+
# Step 3: Classify
|
| 99 |
+
elif st.session_state.step_case2 == 3:
|
| 100 |
+
img8 = Image.open("8.png")
|
| 101 |
+
img_display2.image(img8, caption="Classification Result", use_column_width=True)
|
| 102 |
+
if st.button("Next: Predict Audio"):
|
| 103 |
+
st.session_state.step_case2 += 1
|
| 104 |
+
|
| 105 |
+
# Step 4: Predict Audio
|
| 106 |
+
elif st.session_state.step_case2 == 4:
|
| 107 |
+
st.audio("1.wav", format="audio/wav")
|
| 108 |
+
st.audio("2.wav", format="audio/wav")
|
| 109 |
+
st.audio("3.wav", format="audio/wav")
|
| 110 |
+
if st.button("Next: Display Score"):
|
| 111 |
+
st.session_state.step_case2 += 1
|
| 112 |
+
|
| 113 |
+
# Step 5: Display Score
|
| 114 |
+
elif st.session_state.step_case2 == 5:
|
| 115 |
+
st.success("Score: 0.750 / 1.0")
|