Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
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(
|
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
|
80 |
-
if st.button("Read
|
81 |
-
if
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
88 |
else:
|
89 |
-
st.warning("
|
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"):
|