awacke1 commited on
Commit
c4c0ccb
โ€ข
1 Parent(s): 9e301bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
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, row_idx):
20
  return f'''
21
  <!DOCTYPE html>
22
  <html>
23
  <head>
24
  <title>Read It Aloud</title>
25
  <script type="text/javascript">
26
- function readAloud{row_idx}() {{
27
- const text = document.getElementById("textArea{row_idx}").value;
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{row_idx}" rows="10" cols="80">
36
  {text_to_speak}
37
  </textarea>
38
  <br>
39
- <button onclick="readAloud{row_idx}()">๐Ÿ”Š Read Aloud</button>
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
- if st.button("Search ๐Ÿ•ต๏ธโ€โ™€๏ธ"):
79
- filtered_data = filter_by_keyword(data, search_keyword)
80
- st.write(f"Filtered Dataset by '{search_keyword}' ๐Ÿ“Š")
81
- st.dataframe(filtered_data)
82
- if not filtered_data.empty:
83
- html_blocks = []
84
- for idx, row in filtered_data.iterrows():
85
- question_text = row.get("question", "No question field")
86
- documentHTML5 = generate_html_with_textarea(question_text, idx)
87
- html_blocks.append(documentHTML5)
88
- all_html = ''.join(html_blocks)
89
- components.html(all_html, width=1280, height=1024)
 
 
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