awacke1 commited on
Commit
415e3b3
β€’
1 Parent(s): 2e511c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -22
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 = []
@@ -16,8 +20,7 @@ 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(row):
20
- first_three_columns_text = ' '.join([f"{col}: {row[col]}" for col in row.index[:3]])
21
  return f'''
22
  <!DOCTYPE html>
23
  <html>
@@ -34,7 +37,7 @@ def generate_html_with_textarea(row):
34
  <body>
35
  <h1>πŸ”Š Read It Aloud</h1>
36
  <textarea id="textArea" rows="10" cols="80">
37
- {first_three_columns_text}
38
  </textarea>
39
  <br>
40
  <button onclick="readAloud()">πŸ”Š Read Aloud</button>
@@ -58,16 +61,6 @@ data = large_data if file_option == "usmle_16.2MB.jsonl" else small_data
58
  # Top 20 healthcare terms for USMLE
59
  top_20_terms = ['Heart', 'Lung', 'Pain', 'Memory', 'Kidney', 'Diabetes', 'Cancer', 'Infection', 'Virus', 'Bacteria', 'Gastrointestinal', 'Skin', 'Blood', 'Surgery']
60
 
61
- # Initialize session state for tracking the clicked row in DataFrame
62
- if 'clicked_row' not in st.session_state:
63
- st.session_state['clicked_row'] = None
64
-
65
- # Function to display the DataFrame and capture clicks
66
- def display_clickable_dataframe(df):
67
- for idx, row in df.iterrows():
68
- if st.button(f"Row {idx}", key=f"row_{idx}"):
69
- st.session_state['clicked_row'] = row
70
-
71
  # Create Expander and Columns UI for terms
72
  with st.expander("Search by Common Terms πŸ“š"):
73
  cols = st.columns(4)
@@ -76,21 +69,42 @@ 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
- display_clickable_dataframe(filtered_data)
80
-
81
- # Display the HTML content for the clicked row
82
- if st.session_state['clicked_row'] is not None:
83
- html_content = generate_html_with_textarea(st.session_state['clicked_row'])
84
- components.html(html_content, width=1280, height=1024)
 
 
 
 
85
 
86
  # Text input for search keyword
87
  search_keyword = st.text_input("Or, enter a keyword to filter data:")
88
  if st.button("Search πŸ•΅οΈβ€β™€οΈ"):
89
  filtered_data = filter_by_keyword(data, search_keyword)
90
  st.write(f"Filtered Dataset by '{search_keyword}' πŸ“Š")
91
- display_clickable_dataframe(filtered_data)
 
 
 
 
 
 
 
 
 
92
 
93
-
 
 
 
 
 
 
 
 
94
 
95
  # Markdown and emojis for the case presentation
96
  st.markdown("# πŸ₯ Case Study: 32-year-old Woman's Wellness Check")
@@ -137,4 +151,4 @@ if st.button("Submit"):
137
  st.error("Incorrect. 😞")
138
  st.markdown("""
139
  The best next step is **Ultrasound with Doppler**.
140
- """)
 
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 = []
 
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>
 
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)
 
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
+ # Inject HTML5 and JavaScript for styling
101
+ st.markdown("""
102
+ <style>
103
+ .big-font {
104
+ font-size:24px !important;
105
+ }
106
+ </style>
107
+ """, unsafe_allow_html=True)
108
 
109
  # Markdown and emojis for the case presentation
110
  st.markdown("# πŸ₯ Case Study: 32-year-old Woman's Wellness Check")
 
151
  st.error("Incorrect. 😞")
152
  st.markdown("""
153
  The best next step is **Ultrasound with Doppler**.
154
+ """)