awacke1 commited on
Commit
e477a54
โ€ข
1 Parent(s): 237726d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -22
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
- # Your existing expander and columns UI
 
 
 
 
 
 
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
- # Modified part: Display each row with a button
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 there's a selected row and it's in the filtered data
75
- if st.session_state['last_clicked_row'] in filtered_data.index:
76
- row = filtered_data.loc[st.session_state['last_clicked_row']]
77
- question_text = row.get("question", "No question field")
78
- documentHTML5 = generate_html_with_textarea(question_text)
79
- components.html(documentHTML5, width=1280, height=1024)
80
 
81
- # Text input for search keyword
82
- search_keyword = st.text_input("Or, enter a keyword to filter data:")
83
- if st.button("Search ๐Ÿ•ต๏ธโ€โ™€๏ธ"):
84
- filtered_data = filter_by_keyword(data, search_keyword)
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