awacke1 commited on
Commit
8927802
โ€ข
1 Parent(s): e21a683

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +115 -122
backupapp.py CHANGED
@@ -1,18 +1,8 @@
1
  import streamlit as st
2
  import json
3
  import pandas as pd
4
- import plotly.express as px
5
- import seaborn as sns
6
- import matplotlib.pyplot as plt
7
  import streamlit.components.v1 as components
8
 
9
- # Global variable to hold selected row index
10
- selected_row_index = None
11
-
12
- # Initialize an empty DataFrame
13
- filtered_data = pd.DataFrame()
14
-
15
-
16
  # Function to load JSONL file into a DataFrame
17
  def load_jsonl(file_path):
18
  data = []
@@ -25,132 +15,135 @@ def load_jsonl(file_path):
25
  def filter_by_keyword(df, keyword):
26
  return df[df.apply(lambda row: row.astype(str).str.contains(keyword).any(), axis=1)]
27
 
28
- # Streamlit App
29
- st.title("Medical Licensing Exam Explorer with Speech Synthesis, Plotly and Seaborn ๐Ÿ“Š")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  # Dropdown for file selection
32
- file_option = st.selectbox("Select file:", ["small_file.jsonl", "large_file.jsonl"])
33
  st.write(f"You selected: {file_option}")
34
 
35
- # Load the data
36
- small_data = load_jsonl("usmle_16.2MB.jsonl")
37
- large_data = load_jsonl("usmle_2.08MB.jsonl")
38
-
39
- # Show filtered data grid
40
- if file_option == "small_file.jsonl":
41
- data = small_data
42
- else:
43
- data = large_data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  # Text input for search keyword
46
- search_keyword = st.text_input("Enter a keyword to filter data (e.g., Heart, Lung, Pain, Memory):")
47
-
48
- # Button to trigger search
49
- if st.button("Search"):
50
  filtered_data = filter_by_keyword(data, search_keyword)
51
- st.write(f"Filtered Dataset by '{search_keyword}'")
52
- selected_data = st.dataframe(filtered_data)
53
-
54
-
55
-
56
- def generate_html_with_textarea(text_to_speak):
57
- return f'''
58
- <!DOCTYPE html>
59
- <html>
60
- <head>
61
- <title>Read It Aloud</title>
62
- <script type="text/javascript">
63
- function readAloud() {{
64
- const text = document.getElementById("textArea").value;
65
- const speech = new SpeechSynthesisUtterance(text);
66
- window.speechSynthesis.speak(speech);
67
- }}
68
- </script>
69
- </head>
70
- <body>
71
- <h1>๐Ÿ”Š Read It Aloud</h1>
72
- <textarea id="textArea" rows="10" cols="80">
73
- {text_to_speak}
74
- </textarea>
75
- <br>
76
- <button onclick="readAloud()">๐Ÿ”Š Read Aloud</button>
77
- </body>
78
- </html>
79
- '''
80
-
81
- # Define your text passage
82
- text_passage = "A 60-year-old man is brought to the emergency department by police officers because he was acting strangely in public. The patient was found talking nonsensically to characters on cereal boxes in the store. Past medical history is significant for multiple hospitalizations for alcohol-related injuries and seizures. The patientโ€™s vital signs are within normal limits. Physical examination shows a disheveled male who is oriented to person, but not time or place. Neurologic examination shows nystagmus and severe gait ataxia. A T1/T2 MRI is performed and demonstrates evidence of damage to the mammillary bodies. The patient is given the appropriate treatment for recovering most of his cognitive functions. However, significant short-term memory deficits persist. The patient remembers events from his past such as the school and college he attended, his current job, and the names of family members quite well. Which of the following is the most likely diagnosis in this patient?"
83
-
84
- # Generate HTML code
85
- documentHTML5 = generate_html_with_textarea(text_passage)
86
-
87
-
88
- # Button to read all filtered rows
89
- if st.button("Read All Rows"):
90
  if not filtered_data.empty:
91
  html_blocks = []
92
  for idx, row in filtered_data.iterrows():
93
  question_text = row.get("question", "No question field")
94
- documentHTML5 = generate_html(question_text, "", idx)
95
  html_blocks.append(documentHTML5)
96
  all_html = ''.join(html_blocks)
97
  components.html(all_html, width=1280, height=1024)
98
- else:
99
- st.warning("No rows to read.")
100
-
101
-
102
- # Insert the HTML into Streamlit
103
- # Button to read all filtered rows
104
- if st.button("Read Aloud Text"):
105
- components.html(documentHTML5, width=1280, height=1024)
106
-
107
-
108
- # Plotly and Seaborn charts for EDA
109
- if st.button("Generate Charts"):
110
- st.subheader("Plotly Charts ๐Ÿ“ˆ")
111
-
112
- # 1. Scatter Plot
113
- fig = px.scatter(data, x=data.columns[0], y=data.columns[1])
114
- st.plotly_chart(fig)
115
-
116
- # 2. Line Plot
117
- fig = px.line(data, x=data.columns[0], y=data.columns[1])
118
- st.plotly_chart(fig)
119
 
120
- # 3. Bar Plot
121
- fig = px.bar(data, x=data.columns[0], y=data.columns[1])
122
- st.plotly_chart(fig)
123
 
124
- # 4. Histogram
125
- fig = px.histogram(data, x=data.columns[0])
126
- st.plotly_chart(fig)
127
 
128
- # 5. Box Plot
129
- fig = px.box(data, x=data.columns[0], y=data.columns[1])
130
- st.plotly_chart(fig)
131
-
132
- st.subheader("Seaborn Charts ๐Ÿ“Š")
133
-
134
- # 6. Violin Plot
135
- fig, ax = plt.subplots()
136
- sns.violinplot(x=data.columns[0], y=data.columns[1], data=data)
137
- st.pyplot(fig)
138
-
139
- # 7. Swarm Plot
140
- fig, ax = plt.subplots()
141
- sns.swarmplot(x=data.columns[0], y=data.columns[1], data=data)
142
- st.pyplot(fig)
143
-
144
- # 8. Pair Plot
145
- fig = sns.pairplot(data)
146
- st.pyplot(fig)
147
-
148
- # 9. Heatmap
149
- fig, ax = plt.subplots()
150
- sns.heatmap(data.corr(), annot=True)
151
- st.pyplot(fig)
152
-
153
- # 10. Regplot (Regression Plot)
154
- fig, ax = plt.subplots()
155
- sns.regplot(x=data.columns[0], y=data.columns[1], data=data)
156
- st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import json
3
  import pandas as pd
 
 
 
4
  import streamlit.components.v1 as components
5
 
 
 
 
 
 
 
 
6
  # Function to load JSONL file into a DataFrame
7
  def load_jsonl(file_path):
8
  data = []
 
15
  def filter_by_keyword(df, keyword):
16
  return df[df.apply(lambda row: row.astype(str).str.contains(keyword).any(), axis=1)]
17
 
18
+ # Function to generate HTML with textarea
19
+ def generate_html_with_textarea(text_to_speak):
20
+ return f'''
21
+ <!DOCTYPE html>
22
+ <html>
23
+ <head>
24
+ <title>Read It Aloud</title>
25
+ <script type="text/javascript">
26
+ function readAloud() {{
27
+ const text = document.getElementById("textArea").value;
28
+ const speech = new SpeechSynthesisUtterance(text);
29
+ window.speechSynthesis.speak(speech);
30
+ }}
31
+ </script>
32
+ </head>
33
+ <body>
34
+ <h1>๐Ÿ”Š Read It Aloud</h1>
35
+ <textarea id="textArea" rows="10" cols="80">
36
+ {text_to_speak}
37
+ </textarea>
38
+ <br>
39
+ <button onclick="readAloud()">๐Ÿ”Š Read Aloud</button>
40
+ </body>
41
+ </html>
42
+ '''
43
+
44
+ # Streamlit App ๐Ÿš€
45
+ st.title("USMLE Medical Questions Explorer with Speech Synthesis ๐ŸŽ™")
46
 
47
  # Dropdown for file selection
48
+ file_option = st.selectbox("Select file:", ["usmle_16.2MB.jsonl", "usmle_2.08MB.jsonl"])
49
  st.write(f"You selected: {file_option}")
50
 
51
+ # Load data
52
+ large_data = load_jsonl("usmle_16.2MB.jsonl")
53
+ small_data = load_jsonl("usmle_2.08MB.jsonl")
54
+
55
+ data = large_data if file_option == "usmle_16.2MB.jsonl" else small_data
56
+
57
+ # Top 20 healthcare terms for USMLE
58
+ top_20_terms = ['Heart', 'Lung', 'Pain', 'Memory', 'Kidney', 'Diabetes', 'Cancer', 'Infection', 'Virus', 'Bacteria', 'Neurology', 'Psychiatry', 'Gastrointestinal', 'Pediatrics', 'Oncology', 'Skin', 'Blood', 'Surgery', 'Epidemiology', 'Genetics']
59
+
60
+ # Create Expander and Columns UI for terms
61
+ with st.expander("Search by Common Terms ๐Ÿ“š"):
62
+ cols = st.columns(4)
63
+ for term in top_20_terms:
64
+ with cols[top_20_terms.index(term) % 4]:
65
+ if st.button(f"{term}"):
66
+ filtered_data = filter_by_keyword(data, term)
67
+ st.write(f"Filtered Dataset by '{term}' ๐Ÿ“Š")
68
+ st.dataframe(filtered_data)
69
+ if not filtered_data.empty:
70
+ html_blocks = []
71
+ for idx, row in filtered_data.iterrows():
72
+ question_text = row.get("question", "No question field")
73
+ documentHTML5 = generate_html_with_textarea(question_text)
74
+ html_blocks.append(documentHTML5)
75
+ all_html = ''.join(html_blocks)
76
+ components.html(all_html, width=1280, height=1024)
77
 
78
  # Text input for search keyword
79
+ search_keyword = st.text_input("Or, enter a keyword to filter data:")
80
+ if st.button("Search ๐Ÿ•ต๏ธโ€โ™€๏ธ"):
 
 
81
  filtered_data = filter_by_keyword(data, search_keyword)
82
+ st.write(f"Filtered Dataset by '{search_keyword}' ๐Ÿ“Š")
83
+ st.dataframe(filtered_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  if not filtered_data.empty:
85
  html_blocks = []
86
  for idx, row in filtered_data.iterrows():
87
  question_text = row.get("question", "No question field")
88
+ documentHTML5 = generate_html_with_textarea(question_text)
89
  html_blocks.append(documentHTML5)
90
  all_html = ''.join(html_blocks)
91
  components.html(all_html, width=1280, height=1024)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
 
 
 
93
 
 
 
 
94
 
95
+ # Inject HTML5 and JavaScript for styling
96
+ st.markdown("""
97
+ <style>
98
+ .big-font {
99
+ font-size:24px !important;
100
+ }
101
+ </style>
102
+ """, unsafe_allow_html=True)
103
+
104
+ # Markdown and emojis for the case presentation
105
+ st.markdown("# ๐Ÿฅ Case Study: 32-year-old Woman's Wellness Check")
106
+ st.markdown("## ๐Ÿ“‹ Patient Information")
107
+ st.markdown("""
108
+ - **Age**: 32
109
+ - **Gender**: Female
110
+ - **Past Medical History**: Asthma, Hypertension, Anxiety
111
+ - **Current Medications**: Albuterol, Fluticasone, Hydrochlorothiazide, Lisinopril, Fexofenadine
112
+ - **Vitals**
113
+ - **Temperature**: 99.5ยฐF (37.5ยฐC)
114
+ - **Blood Pressure**: 165/95 mmHg
115
+ - **Pulse**: 70/min
116
+ - **Respirations**: 15/min
117
+ - **Oxygen Saturation**: 98% on room air
118
+ """)
119
+
120
+ # Clinical Findings
121
+ st.markdown("## ๐Ÿ“‹ Clinical Findings")
122
+ st.markdown("""
123
+ - Cardiac exam reveals a S1 and S2 heart sound with a normal rate.
124
+ - Pulmonary exam is clear to auscultation bilaterally with good air movement.
125
+ - Abdominal exam reveals a bruit, normoactive bowel sounds, and an audible borborygmus.
126
+ - Neurological exam reveals cranial nerves II-XII as grossly intact with normal strength and reflexes in the upper and lower extremities.
127
+ """)
128
+
129
+ # Next Step Options
130
+ st.markdown("## ๐Ÿค” What is the best next step in management?")
131
+
132
+ # Multiple Choice
133
+ options = ["Blood Test", "MRI Scan", "Ultrasound with Doppler", "Immediate Surgery"]
134
+ choice = st.selectbox("", options)
135
+
136
+ # Explanation
137
+ if st.button("Submit"):
138
+ if choice == "Ultrasound with Doppler":
139
+ st.success("Correct! ๐ŸŽ‰")
140
+ st.markdown("""
141
+ ### Explanation
142
+ The patient's high blood pressure coupled with an abdominal bruit suggests the possibility of renal artery stenosis.
143
+ An **Ultrasound with Doppler** is the best next step for assessing blood flow and evaluating for renal artery stenosis.
144
+ """)
145
+ else:
146
+ st.error("Incorrect. ๐Ÿ˜ž")
147
+ st.markdown("""
148
+ The best next step is **Ultrasound with Doppler**.
149
+ """)