stcoats commited on
Commit
895e3ae
·
1 Parent(s): a671301

Add application file

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -38,17 +38,17 @@ except Exception as e:
38
  st.stop()
39
 
40
  # Search
41
- query = st.text_input("Search text (case-insensitive)", "").strip().lower()
42
 
43
- # Perform search
44
  if query:
 
45
  sql = """
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 ?
49
  LIMIT 100
50
  """
51
- df = con.execute(sql, [f"%{query}%"]).df()
52
  else:
53
  df = con.execute("""
54
  SELECT id, channel, video_id, speaker, start_time, end_time, upload_date, text, pos_tags, audio
@@ -61,7 +61,7 @@ st.markdown(f"### Showing {len(df)} results")
61
  if len(df) == 0:
62
  st.warning("No matches found.")
63
  else:
64
- def render_audio_cell(audio_bytes):
65
  try:
66
  if isinstance(audio_bytes, (bytes, bytearray, memoryview)):
67
  data = bytes(audio_bytes)
@@ -72,15 +72,20 @@ else:
72
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
73
  tmp.write(data)
74
  tmp.flush()
75
- return f'<audio controls style="height:20px;"> <source src="file://{tmp.name}" type="audio/mpeg"></audio>'
76
  except Exception:
77
  return ""
78
 
79
- df["Audio"] = df["audio"].apply(render_audio_cell)
80
- df_display = df[["id", "channel", "video_id", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags", "Audio"]].copy()
81
 
82
- # Adjust column widths to make room for audio
83
  st.markdown("### Results Table (Sortable with Audio Column)")
84
  st.markdown("(Scroll right to view audio controls)")
85
- st.dataframe(df_display.drop(columns=["audio"]))
 
 
 
 
 
 
86
 
 
38
  st.stop()
39
 
40
  # Search
41
+ query = st.text_input("Search text (case-insensitive)", "").strip()
42
 
 
43
  if query:
44
+ query_like = f"%{query.lower()}%"
45
  sql = """
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 ?
49
  LIMIT 100
50
  """
51
+ df = con.execute(sql, [query_like]).df()
52
  else:
53
  df = con.execute("""
54
  SELECT id, channel, video_id, speaker, start_time, end_time, upload_date, text, pos_tags, audio
 
61
  if len(df) == 0:
62
  st.warning("No matches found.")
63
  else:
64
+ def render_audio(audio_bytes):
65
  try:
66
  if isinstance(audio_bytes, (bytes, bytearray, memoryview)):
67
  data = bytes(audio_bytes)
 
72
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
73
  tmp.write(data)
74
  tmp.flush()
75
+ return f'<audio controls style="height:20px; width:100px;"> <source src="file://{tmp.name}" type="audio/mpeg"></audio>'
76
  except Exception:
77
  return ""
78
 
79
+ df["Audio"] = df["audio"].apply(render_audio)
80
+ df_display = df.drop(columns=["audio"]).copy()
81
 
 
82
  st.markdown("### Results Table (Sortable with Audio Column)")
83
  st.markdown("(Scroll right to view audio controls)")
84
+
85
+ st.dataframe(df_display.drop(columns=["Audio"]))
86
+
87
+ st.markdown("### Audio Previews")
88
+ for i, row in df_display.iterrows():
89
+ st.markdown(f"**{row['speaker']} | {row['text']}**")
90
+ st.markdown(df.loc[i, "Audio"], unsafe_allow_html=True)
91