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

Add application file

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -37,18 +37,18 @@ except Exception as e:
37
  st.error(f"DuckDB connection failed: {e}")
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,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(audio_bytes):
65
  try:
66
  if isinstance(audio_bytes, (bytes, bytearray, memoryview)):
67
  data = bytes(audio_bytes)
@@ -72,20 +72,22 @@ 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; 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
 
 
37
  st.error(f"DuckDB connection failed: {e}")
38
  st.stop()
39
 
40
+ # Search input
41
  query = st.text_input("Search text (case-insensitive)", "").strip()
42
 
43
+ # Build query
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 LOWER(?)
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
  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
  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.drop(columns=["audio"]) # Drop binary column before display
81
+
82
+ # Reorder columns for display
83
+ df_display = df_display[["id", "channel", "video_id", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags", "Audio"]]
84
 
85
  st.markdown("### Results Table (Sortable with Audio Column)")
86
  st.markdown("(Scroll right to view audio controls)")
87
+ st.dataframe(df_display, use_container_width=True)
88
 
89
+ # Optionally, render inline HTML audio
90
+ # for i, row in df_display.iterrows():
91
+ # st.markdown(f"**{row['speaker']} | {row['text']}**")
92
+ # st.markdown(row["Audio"], unsafe_allow_html=True)
 
 
93