Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,10 @@ 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 = []
|
@@ -11,15 +15,12 @@ def load_jsonl(file_path):
|
|
11 |
data.append(json.loads(line))
|
12 |
return pd.DataFrame(data)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# Your filtering logic here
|
18 |
-
return data[data['column_name'].str.contains(term)]
|
19 |
|
20 |
# Function to generate HTML with textarea
|
21 |
-
def generate_html_with_textarea(
|
22 |
-
first_three_columns_text = ' '.join([f"{col}: {row[col]}" for col in row.index[:3]])
|
23 |
return f'''
|
24 |
<!DOCTYPE html>
|
25 |
<html>
|
@@ -36,16 +37,14 @@ def generate_html_with_textarea(row):
|
|
36 |
<body>
|
37 |
<h1>π Read It Aloud</h1>
|
38 |
<textarea id="textArea" rows="10" cols="80">
|
39 |
-
{
|
40 |
</textarea>
|
41 |
<br>
|
42 |
<button onclick="readAloud()">π Read Aloud</button>
|
43 |
</body>
|
44 |
</html>
|
45 |
'''
|
46 |
-
filtered_data = pd.DataFrame()
|
47 |
|
48 |
-
|
49 |
# Streamlit App π
|
50 |
st.title("AI Medical Explorer with Speech Synthesis π")
|
51 |
|
@@ -62,13 +61,7 @@ data = large_data if file_option == "usmle_16.2MB.jsonl" else small_data
|
|
62 |
# Top 20 healthcare terms for USMLE
|
63 |
top_20_terms = ['Heart', 'Lung', 'Pain', 'Memory', 'Kidney', 'Diabetes', 'Cancer', 'Infection', 'Virus', 'Bacteria', 'Gastrointestinal', 'Skin', 'Blood', 'Surgery']
|
64 |
|
65 |
-
|
66 |
-
# Initialize session state for tracking the last clicked row
|
67 |
-
if 'last_clicked_row' not in st.session_state:
|
68 |
-
st.session_state['last_clicked_row'] = None
|
69 |
-
|
70 |
-
|
71 |
-
# Streamlit app
|
72 |
with st.expander("Search by Common Terms π"):
|
73 |
cols = st.columns(4)
|
74 |
for term in top_20_terms:
|
@@ -76,32 +69,33 @@ with st.expander("Search by Common Terms π"):
|
|
76 |
if st.button(f"{term}"):
|
77 |
filtered_data = filter_by_keyword(data, term)
|
78 |
st.write(f"Filter on '{term}' π")
|
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 |
# Markdown and emojis for the case presentation
|
107 |
st.markdown("# π₯ Case Study: 32-year-old Woman's Wellness Check")
|
|
|
3 |
import pandas as pd
|
4 |
import streamlit.components.v1 as components
|
5 |
|
6 |
+
# Initialize session state for tracking the last clicked row
|
7 |
+
if 'last_clicked_row' not in st.session_state:
|
8 |
+
st.session_state['last_clicked_row'] = None
|
9 |
+
|
10 |
# Function to load JSONL file into a DataFrame
|
11 |
def load_jsonl(file_path):
|
12 |
data = []
|
|
|
15 |
data.append(json.loads(line))
|
16 |
return pd.DataFrame(data)
|
17 |
|
18 |
+
# Function to filter DataFrame by keyword
|
19 |
+
def filter_by_keyword(df, keyword):
|
20 |
+
return df[df.apply(lambda row: row.astype(str).str.contains(keyword).any(), axis=1)]
|
|
|
|
|
21 |
|
22 |
# Function to generate HTML with textarea
|
23 |
+
def generate_html_with_textarea(text_to_speak):
|
|
|
24 |
return f'''
|
25 |
<!DOCTYPE html>
|
26 |
<html>
|
|
|
37 |
<body>
|
38 |
<h1>π Read It Aloud</h1>
|
39 |
<textarea id="textArea" rows="10" cols="80">
|
40 |
+
{text_to_speak}
|
41 |
</textarea>
|
42 |
<br>
|
43 |
<button onclick="readAloud()">π Read Aloud</button>
|
44 |
</body>
|
45 |
</html>
|
46 |
'''
|
|
|
47 |
|
|
|
48 |
# Streamlit App π
|
49 |
st.title("AI Medical Explorer with Speech Synthesis π")
|
50 |
|
|
|
61 |
# Top 20 healthcare terms for USMLE
|
62 |
top_20_terms = ['Heart', 'Lung', 'Pain', 'Memory', 'Kidney', 'Diabetes', 'Cancer', 'Infection', 'Virus', 'Bacteria', 'Gastrointestinal', 'Skin', 'Blood', 'Surgery']
|
63 |
|
64 |
+
# Create Expander and Columns UI for terms
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
with st.expander("Search by Common Terms π"):
|
66 |
cols = st.columns(4)
|
67 |
for term in top_20_terms:
|
|
|
69 |
if st.button(f"{term}"):
|
70 |
filtered_data = filter_by_keyword(data, term)
|
71 |
st.write(f"Filter on '{term}' π")
|
72 |
+
with st.sidebar:
|
73 |
+
st.dataframe(filtered_data)
|
74 |
+
if not filtered_data.empty:
|
75 |
+
html_blocks = []
|
76 |
+
for idx, row in filtered_data.iterrows():
|
77 |
+
question_text = row.get("question", "No question field")
|
78 |
+
documentHTML5 = generate_html_with_textarea(question_text)
|
79 |
+
html_blocks.append(documentHTML5)
|
80 |
+
all_html = ''.join(html_blocks)
|
81 |
+
components.html(all_html, width=1280, height=1024)
|
82 |
+
|
83 |
+
# Text input for search keyword
|
84 |
+
search_keyword = st.text_input("Or, enter a keyword to filter data:")
|
85 |
+
if st.button("Search π΅οΈββοΈ"):
|
86 |
+
filtered_data = filter_by_keyword(data, search_keyword)
|
87 |
+
st.write(f"Filtered Dataset by '{search_keyword}' π")
|
88 |
+
st.dataframe(filtered_data)
|
89 |
+
if not filtered_data.empty:
|
90 |
+
html_blocks = []
|
91 |
+
for idx, row in filtered_data.iterrows():
|
92 |
+
question_text = row.get("question", "No question field")
|
93 |
+
documentHTML5 = generate_html_with_textarea(question_text)
|
94 |
+
html_blocks.append(documentHTML5)
|
95 |
+
all_html = ''.join(html_blocks)
|
96 |
+
components.html(all_html, width=1280, height=1024)
|
97 |
+
|
98 |
+
|
99 |
|
100 |
# Markdown and emojis for the case presentation
|
101 |
st.markdown("# π₯ Case Study: 32-year-old Woman's Wellness Check")
|