Update backupapp.py
Browse files- backupapp.py +53 -36
backupapp.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,6 @@ 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,18 +51,60 @@ if st.button("Search"):
|
|
76 |
st.write(f"Filtered Dataset by '{search_keyword}'")
|
77 |
selected_data = st.dataframe(filtered_data)
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
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"):
|
93 |
st.subheader("Plotly 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 |
# Streamlit App
|
29 |
st.title("Medical Licensing Exam Explorer with Speech Synthesis, Plotly and Seaborn 📊")
|
30 |
|
|
|
51 |
st.write(f"Filtered Dataset by '{search_keyword}'")
|
52 |
selected_data = st.dataframe(filtered_data)
|
53 |
|
54 |
+
|
55 |
+
|
56 |
+
def generate_html_with_textarea(text_to_speak):
|
57 |
+
return f'''
|
58 |
+
<!DOCTYPE html>
|
59 |
+
<html>
|
60 |
+
<head>
|
61 |
+
<title>Read It Aloud</title>
|
62 |
+
<script type="text/javascript">
|
63 |
+
function readAloud() {{
|
64 |
+
const text = document.getElementById("textArea").value;
|
65 |
+
const speech = new SpeechSynthesisUtterance(text);
|
66 |
+
window.speechSynthesis.speak(speech);
|
67 |
+
}}
|
68 |
+
</script>
|
69 |
+
</head>
|
70 |
+
<body>
|
71 |
+
<h1>🔊 Read It Aloud</h1>
|
72 |
+
<textarea id="textArea" rows="10" cols="80">
|
73 |
+
{text_to_speak}
|
74 |
+
</textarea>
|
75 |
+
<br>
|
76 |
+
<button onclick="readAloud()">🔊 Read Aloud</button>
|
77 |
+
</body>
|
78 |
+
</html>
|
79 |
+
'''
|
80 |
+
|
81 |
+
# Define your text passage
|
82 |
+
text_passage = "A 60-year-old man is brought to the emergency department by police officers because he was acting strangely in public. The patient was found talking nonsensically to characters on cereal boxes in the store. Past medical history is significant for multiple hospitalizations for alcohol-related injuries and seizures. The patient’s vital signs are within normal limits. Physical examination shows a disheveled male who is oriented to person, but not time or place. Neurologic examination shows nystagmus and severe gait ataxia. A T1/T2 MRI is performed and demonstrates evidence of damage to the mammillary bodies. The patient is given the appropriate treatment for recovering most of his cognitive functions. However, significant short-term memory deficits persist. The patient remembers events from his past such as the school and college he attended, his current job, and the names of family members quite well. Which of the following is the most likely diagnosis in this patient?"
|
83 |
+
|
84 |
+
# Generate HTML code
|
85 |
+
documentHTML5 = generate_html_with_textarea(text_passage)
|
86 |
+
|
87 |
+
|
88 |
+
# Button to read all filtered rows
|
89 |
+
if st.button("Read All Rows"):
|
90 |
+
if not filtered_data.empty:
|
91 |
+
html_blocks = []
|
92 |
+
for idx, row in filtered_data.iterrows():
|
93 |
+
question_text = row.get("question", "No question field")
|
94 |
+
documentHTML5 = generate_html(question_text, "", idx)
|
95 |
+
html_blocks.append(documentHTML5)
|
96 |
+
all_html = ''.join(html_blocks)
|
97 |
+
components.html(all_html, width=1280, height=1024)
|
98 |
else:
|
99 |
+
st.warning("No rows to read.")
|
100 |
+
|
101 |
|
102 |
+
# Insert the HTML into Streamlit
|
103 |
+
# Button to read all filtered rows
|
104 |
+
if st.button("Read Aloud Text"):
|
105 |
+
components.html(documentHTML5, width=1280, height=1024)
|
106 |
+
|
107 |
+
|
108 |
# Plotly and Seaborn charts for EDA
|
109 |
if st.button("Generate Charts"):
|
110 |
st.subheader("Plotly Charts 📈")
|