Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,11 @@ import seaborn as sns
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
import streamlit.components.v1 as components
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Function to load JSONL file into a DataFrame
|
12 |
def load_jsonl(file_path):
|
@@ -20,16 +24,17 @@ def load_jsonl(file_path):
|
|
20 |
def filter_by_keyword(df, keyword):
|
21 |
return df[df.apply(lambda row: row.astype(str).str.contains(keyword).any(), axis=1)]
|
22 |
|
|
|
23 |
# Function to generate HTML5 code with embedded text
|
24 |
-
def generate_html(
|
25 |
return f'''
|
26 |
<!DOCTYPE html>
|
27 |
<html>
|
28 |
<head>
|
29 |
<title>Read It Aloud</title>
|
30 |
<script type="text/javascript">
|
31 |
-
function readAloud() {{
|
32 |
-
const text = document.getElementById(
|
33 |
const speech = new SpeechSynthesisUtterance(text);
|
34 |
window.speechSynthesis.speak(speech);
|
35 |
}}
|
@@ -37,22 +42,32 @@ def generate_html(text):
|
|
37 |
</head>
|
38 |
<body>
|
39 |
<h1>๐ Read It Aloud</h1>
|
40 |
-
<
|
41 |
-
|
42 |
-
</
|
43 |
-
<
|
44 |
-
<button onclick="readAloud()">๐ Read Aloud</button>
|
45 |
</body>
|
46 |
</html>
|
47 |
'''
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# Load the data
|
50 |
small_data = load_jsonl("usmle_16.2MB.jsonl")
|
51 |
large_data = load_jsonl("usmle_2.08MB.jsonl")
|
52 |
|
53 |
-
#
|
54 |
-
|
|
|
|
|
|
|
55 |
|
|
|
56 |
# Dropdown for file selection
|
57 |
file_option = st.selectbox("Select file:", ["small_file.jsonl", "large_file.jsonl"])
|
58 |
st.write(f"You selected: {file_option}")
|
@@ -75,11 +90,16 @@ if st.button("Search"):
|
|
75 |
|
76 |
# Button to read selected row aloud
|
77 |
if st.button("Read Selected Row"):
|
78 |
-
|
79 |
-
if
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
82 |
components.html(documentHTML5, width=1280, height=1024)
|
|
|
|
|
83 |
|
84 |
# Plotly and Seaborn charts for EDA
|
85 |
if st.button("Generate Charts"):
|
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
import streamlit.components.v1 as components
|
8 |
|
9 |
+
# Global variable to hold selected row index
|
10 |
+
selected_row_index = None
|
11 |
+
|
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):
|
|
|
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 |
}}
|
|
|
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 |
+
|
56 |
+
# Dropdown for file selection
|
57 |
+
file_option = st.selectbox("Select file:", ["small_file.jsonl", "large_file.jsonl"])
|
58 |
+
st.write(f"You selected: {file_option}")
|
59 |
+
|
60 |
# Load the data
|
61 |
small_data = load_jsonl("usmle_16.2MB.jsonl")
|
62 |
large_data = load_jsonl("usmle_2.08MB.jsonl")
|
63 |
|
64 |
+
# Show filtered data grid
|
65 |
+
if file_option == "small_file.jsonl":
|
66 |
+
data = small_data
|
67 |
+
else:
|
68 |
+
data = large_data
|
69 |
|
70 |
+
|
71 |
# Dropdown for file selection
|
72 |
file_option = st.selectbox("Select file:", ["small_file.jsonl", "large_file.jsonl"])
|
73 |
st.write(f"You selected: {file_option}")
|
|
|
90 |
|
91 |
# Button to read selected row aloud
|
92 |
if st.button("Read Selected Row"):
|
93 |
+
global selected_row_index
|
94 |
+
if selected_row_index is not None:
|
95 |
+
selected_row = filtered_data.loc[selected_row_index]
|
96 |
+
question_text = selected_row.get("question", "No question field")
|
97 |
+
answer_text = selected_row.get("answer", "No answer field")
|
98 |
+
|
99 |
+
documentHTML5 = generate_html(question_text, answer_text)
|
100 |
components.html(documentHTML5, width=1280, height=1024)
|
101 |
+
else:
|
102 |
+
st.warning("Please select a row first.")
|
103 |
|
104 |
# Plotly and Seaborn charts for EDA
|
105 |
if st.button("Generate Charts"):
|