Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,12 +11,14 @@ def load_jsonl(file_path):
|
|
11 |
data.append(json.loads(line))
|
12 |
return pd.DataFrame(data)
|
13 |
|
14 |
-
#
|
15 |
-
def filter_by_keyword(
|
16 |
-
|
|
|
17 |
|
18 |
# Function to generate HTML with textarea
|
19 |
-
def generate_html_with_textarea(
|
|
|
20 |
return f'''
|
21 |
<!DOCTYPE html>
|
22 |
<html>
|
@@ -33,7 +35,7 @@ def generate_html_with_textarea(text_to_speak):
|
|
33 |
<body>
|
34 |
<h1>๐ Read It Aloud</h1>
|
35 |
<textarea id="textArea" rows="10" cols="80">
|
36 |
-
{
|
37 |
</textarea>
|
38 |
<br>
|
39 |
<button onclick="readAloud()">๐ Read Aloud</button>
|
@@ -68,7 +70,7 @@ if 'last_clicked_row' not in st.session_state:
|
|
68 |
st.session_state['last_clicked_row'] = None
|
69 |
|
70 |
|
71 |
-
#
|
72 |
with st.expander("Search by Common Terms ๐"):
|
73 |
cols = st.columns(4)
|
74 |
for term in top_20_terms:
|
@@ -77,35 +79,22 @@ with st.expander("Search by Common Terms ๐"):
|
|
77 |
filtered_data = filter_by_keyword(data, term)
|
78 |
st.write(f"Filter on '{term}' ๐")
|
79 |
|
80 |
-
# Display
|
81 |
-
|
82 |
-
|
83 |
-
st.
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
# Check if 'last_clicked_row' is set and in the filtered data
|
97 |
-
if st.session_state['last_clicked_row'] is not None and st.session_state['last_clicked_row'] in filtered_data.index:
|
98 |
-
# Display details of the selected row in the main area
|
99 |
-
st.write("Selected Row Details:")
|
100 |
-
selected_row = filtered_data.loc[st.session_state['last_clicked_row']]
|
101 |
-
first_three_columns = selected_row.iloc[:3]
|
102 |
-
for col in first_three_columns.index:
|
103 |
-
st.write(f"{col}: {first_three_columns[col]}")
|
104 |
-
|
105 |
-
# Display the HTML content for the selected row
|
106 |
-
components.html(st.session_state['selected_row_html'], width=1280, height=1024)
|
107 |
-
|
108 |
-
|
109 |
|
110 |
# Inject HTML5 and JavaScript for styling
|
111 |
st.markdown("""
|
|
|
11 |
data.append(json.loads(line))
|
12 |
return pd.DataFrame(data)
|
13 |
|
14 |
+
# Your filter_by_keyword function
|
15 |
+
def filter_by_keyword(data, term):
|
16 |
+
# Your filtering logic here
|
17 |
+
return data[data['column_name'].str.contains(term)]
|
18 |
|
19 |
# Function to generate HTML with textarea
|
20 |
+
def generate_html_with_textarea(row):
|
21 |
+
first_three_columns_text = ' '.join([f"{col}: {row[col]}" for col in row.index[:3]])
|
22 |
return f'''
|
23 |
<!DOCTYPE html>
|
24 |
<html>
|
|
|
35 |
<body>
|
36 |
<h1>๐ Read It Aloud</h1>
|
37 |
<textarea id="textArea" rows="10" cols="80">
|
38 |
+
{first_three_columns_text}
|
39 |
</textarea>
|
40 |
<br>
|
41 |
<button onclick="readAloud()">๐ Read Aloud</button>
|
|
|
70 |
st.session_state['last_clicked_row'] = None
|
71 |
|
72 |
|
73 |
+
# Streamlit app
|
74 |
with st.expander("Search by Common Terms ๐"):
|
75 |
cols = st.columns(4)
|
76 |
for term in top_20_terms:
|
|
|
79 |
filtered_data = filter_by_keyword(data, term)
|
80 |
st.write(f"Filter on '{term}' ๐")
|
81 |
|
82 |
+
# Display clickable rows in the dataframe
|
83 |
+
for idx, row in filtered_data.iterrows():
|
84 |
+
link = f"[Row {idx}]('javascript:void(0);')"
|
85 |
+
st.markdown(link, unsafe_allow_html=True)
|
86 |
+
|
87 |
+
# Capture the clicked row index
|
88 |
+
row_index = st.experimental_get_query_params().get("row_index")
|
89 |
+
if row_index:
|
90 |
+
selected_row = filtered_data.loc[int(row_index[0])]
|
91 |
+
html_content = generate_html_with_textarea(selected_row)
|
92 |
+
components.html(html_content, width=1280, height=1024)
|
93 |
+
|
94 |
+
# Always show the first row
|
95 |
+
if not filtered_data.empty:
|
96 |
+
first_row_html = generate_html_with_textarea(filtered_data.iloc[0])
|
97 |
+
components.html(first_row_html, width=1280, height=1024)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
# Inject HTML5 and JavaScript for styling
|
100 |
st.markdown("""
|