stcoats commited on
Commit
4c9a1f3
·
1 Parent(s): 56677fa

Add application file

Browse files
Files changed (1) hide show
  1. app.py +11 -31
app.py CHANGED
@@ -40,12 +40,15 @@ except Exception as e:
40
  # Search input
41
  query = st.text_input("Search text (case-insensitive, exact substring match)", "").strip()
42
 
43
- # Build query
 
 
 
44
  if query:
45
  sql = f"""
46
  SELECT id, channel, video_id, speaker, start_time, end_time, upload_date, text, pos_tags, audio
47
  FROM data
48
- WHERE LOWER(text) LIKE LOWER('%{query}%')
49
  LIMIT 100
50
  """
51
  df = con.execute(sql).df()
@@ -77,35 +80,12 @@ else:
77
  df["Audio"] = df["audio"].apply(get_audio_html)
78
  df.drop(columns=["audio"], inplace=True)
79
 
80
- from streamlit.components.v1 import html
81
-
82
- def display_table_with_audio(df):
83
- table_html = """
84
- <table border='1' style='border-collapse:collapse;width:100%;font-size:13px;'>
85
- <thead>
86
- <tr>
87
- <th style='width:5em;'>id</th>
88
- <th style='width:6em;'>channel</th>
89
- <th style='width:6em;'>video_id</th>
90
- <th style='width:6em;'>speaker</th>
91
- <th style='width:6em;'>start_time</th>
92
- <th style='width:6em;'>end_time</th>
93
- <th style='width:6em;'>upload_date</th>
94
- <th style='width:20em;'>text</th>
95
- <th style='width:8em;'>pos_tags</th>
96
- <th style='width:12em;'>Audio</th>
97
- </tr>
98
- </thead>
99
- <tbody>
100
- """
101
- for _, row in df.iterrows():
102
- table_html += "<tr>"
103
- for col in ["id", "channel", "video_id", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags", "Audio"]:
104
- table_html += f"<td>{row[col]}</td>"
105
- table_html += "</tr>"
106
- table_html += "</tbody></table>"
107
- return table_html
108
 
 
109
  st.markdown("### Results Table (Sortable with Audio Column)")
110
- html(display_table_with_audio(df), height=900, scrolling=True)
 
111
 
 
40
  # Search input
41
  query = st.text_input("Search text (case-insensitive, exact substring match)", "").strip()
42
 
43
+ # Escape single quotes in query
44
+ query_safe = query.replace("'", "''")
45
+
46
+ # Build query using exact substring match only (case-insensitive handled by ILIKE)
47
  if query:
48
  sql = f"""
49
  SELECT id, channel, video_id, speaker, start_time, end_time, upload_date, text, pos_tags, audio
50
  FROM data
51
+ WHERE text ILIKE '%{query_safe}%'
52
  LIMIT 100
53
  """
54
  df = con.execute(sql).df()
 
80
  df["Audio"] = df["audio"].apply(get_audio_html)
81
  df.drop(columns=["audio"], inplace=True)
82
 
83
+ # Reorder columns so "Audio" is last and limit column width for id
84
+ display_cols = ["id", "channel", "video_id", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags", "Audio"]
85
+ df = df[display_cols]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
+ # Show table with HTML rendering for audio
88
  st.markdown("### Results Table (Sortable with Audio Column)")
89
+ st.write("(Scroll right to view audio controls)")
90
+ st.write(df.to_html(escape=False, index=False), unsafe_allow_html=True)
91