awacke1 commited on
Commit
fefca88
ยท
1 Parent(s): 4a66f10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -12,6 +12,7 @@ selected_row_index = None
12
  # Initialize an empty DataFrame
13
  filtered_data = pd.DataFrame()
14
 
 
15
  # Function to load JSONL file into a DataFrame
16
  def load_jsonl(file_path):
17
  data = []
@@ -24,32 +25,30 @@ def load_jsonl(file_path):
24
  def filter_by_keyword(df, keyword):
25
  return df[df.apply(lambda row: row.astype(str).str.contains(keyword).any(), axis=1)]
26
 
27
-
28
  # Function to generate HTML5 code with embedded text
29
- def generate_html(question_text, answer_text):
30
  return f'''
31
  <!DOCTYPE html>
32
  <html>
33
  <head>
34
  <title>Read It Aloud</title>
35
  <script type="text/javascript">
36
- function readAloud(id) {{
37
- const text = document.getElementById(id).innerText;
38
  const speech = new SpeechSynthesisUtterance(text);
39
  window.speechSynthesis.speak(speech);
40
  }}
41
  </script>
42
  </head>
43
  <body>
44
- <h1>๐Ÿ”Š Read It Aloud</h1>
45
- <p id="questionArea">{question_text}</p>
46
- <button onclick="readAloud('questionArea')">๐Ÿ”Š Read Question Aloud</button>
47
- <p id="answerArea">{answer_text}</p>
48
- <button onclick="readAloud('answerArea')">๐Ÿ”Š Read Answer Aloud</button>
49
  </body>
50
  </html>
51
  '''
52
 
 
53
  # Streamlit App
54
  st.title("Medical Licensing Exam Explorer with Speech Synthesis, Plotly and Seaborn ๐Ÿ“Š")
55
 
@@ -76,17 +75,18 @@ if st.button("Search"):
76
  st.write(f"Filtered Dataset by '{search_keyword}'")
77
  selected_data = st.dataframe(filtered_data)
78
 
79
- # Button to read selected row aloud
80
- if st.button("Read Selected Row"):
81
- if selected_row_index is not None:
82
- selected_row = filtered_data.loc[selected_row_index]
83
- question_text = selected_row.get("question", "No question field")
84
- answer_text = selected_row.get("answer", "No answer field")
85
-
86
- documentHTML5 = generate_html(question_text, answer_text)
87
- components.html(documentHTML5, width=1280, height=1024)
 
88
  else:
89
- st.warning("Please select a row first.")
90
 
91
  # Plotly and Seaborn charts for EDA
92
  if st.button("Generate Charts"):
 
12
  # Initialize an empty DataFrame
13
  filtered_data = pd.DataFrame()
14
 
15
+
16
  # Function to load JSONL file into a DataFrame
17
  def load_jsonl(file_path):
18
  data = []
 
25
  def filter_by_keyword(df, keyword):
26
  return df[df.apply(lambda row: row.astype(str).str.contains(keyword).any(), axis=1)]
27
 
 
28
  # Function to generate HTML5 code with embedded text
29
+ def generate_html(question_text, answer_text, idx):
30
  return f'''
31
  <!DOCTYPE html>
32
  <html>
33
  <head>
34
  <title>Read It Aloud</title>
35
  <script type="text/javascript">
36
+ function readAloud{id}() {{
37
+ const text = document.getElementById("questionArea{id}").innerText;
38
  const speech = new SpeechSynthesisUtterance(text);
39
  window.speechSynthesis.speak(speech);
40
  }}
41
  </script>
42
  </head>
43
  <body>
44
+ <h1>๐Ÿ”Š Read It Aloud - Row {idx}</h1>
45
+ <p id="questionArea{id}">{question_text}</p>
46
+ <button onclick="readAloud{id}()">๐Ÿ”Š Read Question Aloud</button>
 
 
47
  </body>
48
  </html>
49
  '''
50
 
51
+
52
  # Streamlit App
53
  st.title("Medical Licensing Exam Explorer with Speech Synthesis, Plotly and Seaborn ๐Ÿ“Š")
54
 
 
75
  st.write(f"Filtered Dataset by '{search_keyword}'")
76
  selected_data = st.dataframe(filtered_data)
77
 
78
+ # Button to read all filtered rows
79
+ if st.button("Read All Rows"):
80
+ if not filtered_data.empty:
81
+ html_blocks = []
82
+ for idx, row in filtered_data.iterrows():
83
+ question_text = row.get("question", "No question field")
84
+ documentHTML5 = generate_html(question_text, "", idx)
85
+ html_blocks.append(documentHTML5)
86
+ all_html = ''.join(html_blocks)
87
+ components.html(all_html, width=1280, height=1024)
88
  else:
89
+ st.warning("No rows to read.")
90
 
91
  # Plotly and Seaborn charts for EDA
92
  if st.button("Generate Charts"):