awacke1 commited on
Commit
04d4dca
β€’
1 Parent(s): 9d841e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -43
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
- # Your filter_by_keyword function
16
- def filter_by_keyword(data, term):
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(row):
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
- {first_three_columns_text}
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
- # Display clickable rows in the dataframe
81
- for idx, row in filtered_data.iterrows():
82
- link = f"[Row {idx}]('javascript:void(0);')"
83
- st.markdown(link, unsafe_allow_html=True)
84
-
85
- # Capture the clicked row index
86
- row_index = st.experimental_get_query_params().get("row_index")
87
- if row_index:
88
- selected_row = filtered_data.loc[int(row_index[0])]
89
- html_content = generate_html_with_textarea(selected_row)
90
- components.html(html_content, width=1280, height=1024)
91
-
92
- # Always show the first row if filtered_data is not empty
93
- if not filtered_data.empty:
94
- first_row_html = generate_html_with_textarea(filtered_data.iloc[0])
95
- components.html(first_row_html, width=1280, height=1024)
96
-
97
- # Inject HTML5 and JavaScript for styling
98
- st.markdown("""
99
- <style>
100
- .big-font {
101
- font-size:24px !important;
102
- }
103
- </style>
104
- """, unsafe_allow_html=True)
 
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")