Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,15 +16,15 @@ def filter_by_keyword(df, keyword):
|
|
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(text_to_speak
|
20 |
return f'''
|
21 |
<!DOCTYPE html>
|
22 |
<html>
|
23 |
<head>
|
24 |
<title>Read It Aloud</title>
|
25 |
<script type="text/javascript">
|
26 |
-
function readAloud
|
27 |
-
const text = document.getElementById("textArea
|
28 |
const speech = new SpeechSynthesisUtterance(text);
|
29 |
window.speechSynthesis.speak(speech);
|
30 |
}}
|
@@ -32,11 +32,11 @@ def generate_html_with_textarea(text_to_speak, row_idx):
|
|
32 |
</head>
|
33 |
<body>
|
34 |
<h1>๐ Read It Aloud</h1>
|
35 |
-
<textarea id="textArea
|
36 |
{text_to_speak}
|
37 |
</textarea>
|
38 |
<br>
|
39 |
-
<button onclick="readAloud
|
40 |
</body>
|
41 |
</html>
|
42 |
'''
|
@@ -75,18 +75,20 @@ with st.expander("Search by Common Terms ๐"):
|
|
75 |
all_html = ''.join(html_blocks)
|
76 |
components.html(all_html, width=1280, height=1024)
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
90 |
|
91 |
|
92 |
|
|
|
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(text_to_speak):
|
20 |
return f'''
|
21 |
<!DOCTYPE html>
|
22 |
<html>
|
23 |
<head>
|
24 |
<title>Read It Aloud</title>
|
25 |
<script type="text/javascript">
|
26 |
+
function readAloud() {{
|
27 |
+
const text = document.getElementById("textArea").value;
|
28 |
const speech = new SpeechSynthesisUtterance(text);
|
29 |
window.speechSynthesis.speak(speech);
|
30 |
}}
|
|
|
32 |
</head>
|
33 |
<body>
|
34 |
<h1>๐ Read It Aloud</h1>
|
35 |
+
<textarea id="textArea" rows="10" cols="80">
|
36 |
{text_to_speak}
|
37 |
</textarea>
|
38 |
<br>
|
39 |
+
<button onclick="readAloud()">๐ Read Aloud</button>
|
40 |
</body>
|
41 |
</html>
|
42 |
'''
|
|
|
75 |
all_html = ''.join(html_blocks)
|
76 |
components.html(all_html, width=1280, height=1024)
|
77 |
|
78 |
+
# Text input for search keyword
|
79 |
+
search_keyword = st.text_input("Or, enter a keyword to filter data:")
|
80 |
+
if st.button("Search ๐ต๏ธโโ๏ธ"):
|
81 |
+
filtered_data = filter_by_keyword(data, search_keyword)
|
82 |
+
st.write(f"Filtered Dataset by '{search_keyword}' ๐")
|
83 |
+
st.dataframe(filtered_data)
|
84 |
+
if not filtered_data.empty:
|
85 |
+
html_blocks = []
|
86 |
+
for idx, row in filtered_data.iterrows():
|
87 |
+
question_text = row.get("question", "No question field")
|
88 |
+
documentHTML5 = generate_html_with_textarea(question_text)
|
89 |
+
html_blocks.append(documentHTML5)
|
90 |
+
all_html = ''.join(html_blocks)
|
91 |
+
components.html(all_html, width=1280, height=1024)
|
92 |
|
93 |
|
94 |
|