Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,6 @@ import json
|
|
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,7 +16,8 @@ def filter_by_keyword(df, keyword):
|
|
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(
|
|
|
24 |
return f'''
|
25 |
<!DOCTYPE html>
|
26 |
<html>
|
@@ -37,7 +34,7 @@ def generate_html_with_textarea(text_to_speak):
|
|
37 |
<body>
|
38 |
<h1>π Read It Aloud</h1>
|
39 |
<textarea id="textArea" rows="10" cols="80">
|
40 |
-
{
|
41 |
</textarea>
|
42 |
<br>
|
43 |
<button onclick="readAloud()">π Read Aloud</button>
|
@@ -61,6 +58,16 @@ data = large_data if file_option == "usmle_16.2MB.jsonl" else small_data
|
|
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,31 +76,19 @@ with st.expander("Search by Common Terms π"):
|
|
69 |
if st.button(f"{term}"):
|
70 |
filtered_data = filter_by_keyword(data, term)
|
71 |
st.write(f"Filter on '{term}' π")
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
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 |
-
|
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 |
|
|
|
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 |
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 |
<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 |
# 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 |
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 |
|