Update app.py
Browse files
app.py
CHANGED
@@ -41,6 +41,11 @@ def generate_html_with_textarea(text_to_speak):
|
|
41 |
</html>
|
42 |
'''
|
43 |
|
|
|
|
|
|
|
|
|
|
|
44 |
# Streamlit App ๐
|
45 |
st.title("AI Medical Explorer with Speech Synthesis ๐")
|
46 |
|
@@ -57,7 +62,13 @@ data = large_data if file_option == "usmle_16.2MB.jsonl" else small_data
|
|
57 |
# Top 20 healthcare terms for USMLE
|
58 |
top_20_terms = ['Heart', 'Lung', 'Pain', 'Memory', 'Kidney', 'Diabetes', 'Cancer', 'Infection', 'Virus', 'Bacteria', 'Gastrointestinal', 'Skin', 'Blood', 'Surgery']
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
with st.expander("Search by Common Terms ๐"):
|
62 |
cols = st.columns(4)
|
63 |
for term in top_20_terms:
|
@@ -66,33 +77,30 @@ with st.expander("Search by Common Terms ๐"):
|
|
66 |
filtered_data = filter_by_keyword(data, term)
|
67 |
st.write(f"Filter on '{term}' ๐")
|
68 |
with st.sidebar:
|
69 |
-
#
|
70 |
for idx, row in filtered_data.iterrows():
|
71 |
if st.button(f"Row {idx}", key=f"row_{idx}"):
|
72 |
st.session_state['last_clicked_row'] = idx
|
73 |
|
74 |
-
# Check if
|
75 |
-
if st.session_state['last_clicked_row'] in filtered_data.index:
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
#
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
st.write(f"Filtered Dataset by '{search_keyword}' ๐")
|
86 |
-
st.dataframe(filtered_data)
|
87 |
-
if not filtered_data.empty:
|
88 |
-
html_blocks = []
|
89 |
-
for idx, row in filtered_data.iterrows():
|
90 |
-
question_text = row.get("question", "No question field")
|
91 |
-
documentHTML5 = generate_html_with_textarea(question_text)
|
92 |
-
html_blocks.append(documentHTML5)
|
93 |
-
all_html = ''.join(html_blocks)
|
94 |
-
components.html(all_html, width=1280, height=1024)
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
|
98 |
# Inject HTML5 and JavaScript for styling
|
|
|
41 |
</html>
|
42 |
'''
|
43 |
|
44 |
+
# Initialize session state for tracking the last clicked row
|
45 |
+
if 'last_clicked_row' not in st.session_state:
|
46 |
+
st.session_state['last_clicked_row'] = None
|
47 |
+
|
48 |
+
|
49 |
# Streamlit App ๐
|
50 |
st.title("AI Medical Explorer with Speech Synthesis ๐")
|
51 |
|
|
|
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 |
+
# Expander UI for common terms
|
72 |
with st.expander("Search by Common Terms ๐"):
|
73 |
cols = st.columns(4)
|
74 |
for term in top_20_terms:
|
|
|
77 |
filtered_data = filter_by_keyword(data, term)
|
78 |
st.write(f"Filter on '{term}' ๐")
|
79 |
with st.sidebar:
|
80 |
+
# Display each row with a button
|
81 |
for idx, row in filtered_data.iterrows():
|
82 |
if st.button(f"Row {idx}", key=f"row_{idx}"):
|
83 |
st.session_state['last_clicked_row'] = idx
|
84 |
|
85 |
+
# Check if 'last_clicked_row' is set and in the filtered data
|
86 |
+
if st.session_state['last_clicked_row'] is not None and st.session_state['last_clicked_row'] in filtered_data.index:
|
87 |
+
selected_row = filtered_data.loc[st.session_state['last_clicked_row']]
|
88 |
+
|
89 |
+
# Extract only the first three columns of the selected row
|
90 |
+
first_three_columns = selected_row.iloc[:3]
|
91 |
|
92 |
+
# Display these columns in the sidebar
|
93 |
+
st.sidebar.write("Selected Row Details:")
|
94 |
+
for col in first_three_columns.index:
|
95 |
+
st.sidebar.write(f"{col}: {first_three_columns[col]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
+
# Concatenate these column values with the question_text
|
98 |
+
additional_info = ' '.join([f"{col}: {val}" for col, val in first_three_columns.items()])
|
99 |
+
question_text = selected_row.get("question", "No question field")
|
100 |
+
full_text = f"{additional_info} Question: {question_text}"
|
101 |
+
|
102 |
+
documentHTML5 = generate_html_with_textarea(full_text)
|
103 |
+
components.html(documentHTML5, width=1280, height=1024)
|
104 |
|
105 |
|
106 |
# Inject HTML5 and JavaScript for styling
|