File size: 6,008 Bytes
4bce033
 
 
af59780
4bce033
 
 
 
 
 
 
 
 
 
 
 
 
9412e3a
c4c0ccb
9412e3a
 
 
 
 
 
c4c0ccb
 
9412e3a
 
 
 
 
 
 
c4c0ccb
9412e3a
 
 
c4c0ccb
9412e3a
 
 
 
e477a54
 
 
 
 
9412e3a
5849061
3fddc37
 
9412e3a
3fddc37
 
9412e3a
 
 
4bce033
0e091b8
4bce033
9412e3a
f436479
725e817
e477a54
 
 
 
 
 
 
9412e3a
 
 
55abb28
9412e3a
 
b0f8dd2
 
e477a54
0e091b8
237726d
 
 
e477a54
 
 
 
 
 
725e817
e477a54
 
 
 
e21a683
e477a54
 
 
 
 
 
 
e21a683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
import streamlit as st
import json
import pandas as pd
import streamlit.components.v1 as components

# Function to load JSONL file into a DataFrame
def load_jsonl(file_path):
    data = []
    with open(file_path, 'r') as f:
        for line in f:
            data.append(json.loads(line))
    return pd.DataFrame(data)

# Function to filter DataFrame by keyword
def filter_by_keyword(df, keyword):
    return df[df.apply(lambda row: row.astype(str).str.contains(keyword).any(), axis=1)]

# Function to generate HTML with textarea
def generate_html_with_textarea(text_to_speak):
    return f'''
    <!DOCTYPE html>
    <html>
    <head>
        <title>Read It Aloud</title>
        <script type="text/javascript">
            function readAloud() {{
                const text = document.getElementById("textArea").value;
                const speech = new SpeechSynthesisUtterance(text);
                window.speechSynthesis.speak(speech);
            }}
        </script>
    </head>
    <body>
        <h1>๐Ÿ”Š Read It Aloud</h1>
        <textarea id="textArea" rows="10" cols="80">
    {text_to_speak}
        </textarea>
        <br>
        <button onclick="readAloud()">๐Ÿ”Š Read Aloud</button>
    </body>
    </html>
    '''

# Initialize session state for tracking the last clicked row
if 'last_clicked_row' not in st.session_state:
    st.session_state['last_clicked_row'] = None

    
# Streamlit App ๐Ÿš€
st.title("AI Medical Explorer with Speech Synthesis ๐ŸŽ™")

# Dropdown for file selection
file_option = st.selectbox("Select file:", ["usmle_16.2MB.jsonl", "usmle_2.08MB.jsonl"])
st.write(f"You selected: {file_option}")

# Load data
large_data = load_jsonl("usmle_16.2MB.jsonl")
small_data = load_jsonl("usmle_2.08MB.jsonl")

data = large_data if file_option == "usmle_16.2MB.jsonl" else small_data

# Top 20 healthcare terms for USMLE
top_20_terms = ['Heart', 'Lung', 'Pain', 'Memory', 'Kidney', 'Diabetes', 'Cancer', 'Infection', 'Virus', 'Bacteria', 'Gastrointestinal', 'Skin', 'Blood', 'Surgery']


# Initialize session state for tracking the last clicked row
if 'last_clicked_row' not in st.session_state:
    st.session_state['last_clicked_row'] = None


# Expander UI for common terms
with st.expander("Search by Common Terms ๐Ÿ“š"):
    cols = st.columns(4)
    for term in top_20_terms:
        with cols[top_20_terms.index(term) % 4]:
            if st.button(f"{term}"):
                filtered_data = filter_by_keyword(data, term)
                st.write(f"Filter on '{term}' ๐Ÿ“Š")
                with st.sidebar:
                    # Display each row with a button
                    for idx, row in filtered_data.iterrows():
                        if st.button(f"Row {idx}", key=f"row_{idx}"):
                            st.session_state['last_clicked_row'] = idx

                # Check if 'last_clicked_row' is set and in the filtered data
                if st.session_state['last_clicked_row'] is not None and st.session_state['last_clicked_row'] in filtered_data.index:
                    selected_row = filtered_data.loc[st.session_state['last_clicked_row']]

                    # Extract only the first three columns of the selected row
                    first_three_columns = selected_row.iloc[:3]

                    # Display these columns in the sidebar
                    st.sidebar.write("Selected Row Details:")
                    for col in first_three_columns.index:
                        st.sidebar.write(f"{col}: {first_three_columns[col]}")

                    # Concatenate these column values with the question_text
                    additional_info = ' '.join([f"{col}: {val}" for col, val in first_three_columns.items()])
                    question_text = selected_row.get("question", "No question field")
                    full_text = f"{additional_info} Question: {question_text}"
                    
                    documentHTML5 = generate_html_with_textarea(full_text)
                    components.html(documentHTML5, width=1280, height=1024)


# Inject HTML5 and JavaScript for styling
st.markdown("""
<style>
    .big-font {
        font-size:24px !important;
    }
</style>
""", unsafe_allow_html=True)

# Markdown and emojis for the case presentation
st.markdown("# ๐Ÿฅ Case Study: 32-year-old Woman's Wellness Check")
st.markdown("## ๐Ÿ“‹ Patient Information")
st.markdown("""
- **Age**: 32
- **Gender**: Female
- **Past Medical History**: Asthma, Hypertension, Anxiety
- **Current Medications**: Albuterol, Fluticasone, Hydrochlorothiazide, Lisinopril, Fexofenadine
- **Vitals**
  - **Temperature**: 99.5ยฐF (37.5ยฐC)
  - **Blood Pressure**: 165/95 mmHg
  - **Pulse**: 70/min
  - **Respirations**: 15/min
  - **Oxygen Saturation**: 98% on room air
""")

# Clinical Findings
st.markdown("## ๐Ÿ“‹ Clinical Findings")
st.markdown("""
- Cardiac exam reveals a S1 and S2 heart sound with a normal rate.
- Pulmonary exam is clear to auscultation bilaterally with good air movement.
- Abdominal exam reveals a bruit, normoactive bowel sounds, and an audible borborygmus.
- Neurological exam reveals cranial nerves II-XII as grossly intact with normal strength and reflexes in the upper and lower extremities.
""")

# Next Step Options
st.markdown("## ๐Ÿค” What is the best next step in management?")

# Multiple Choice
options = ["Blood Test", "MRI Scan", "Ultrasound with Doppler", "Immediate Surgery"]
choice = st.selectbox("", options)

# Explanation
if st.button("Submit"):
    if choice == "Ultrasound with Doppler":
        st.success("Correct! ๐ŸŽ‰")
        st.markdown("""
        ### Explanation
        The patient's high blood pressure coupled with an abdominal bruit suggests the possibility of renal artery stenosis.
        An **Ultrasound with Doppler** is the best next step for assessing blood flow and evaluating for renal artery stenosis.
        """)
    else:
        st.error("Incorrect. ๐Ÿ˜ž")
        st.markdown("""
        The best next step is **Ultrasound with Doppler**.
        """)