stcoats commited on
Commit
9302019
·
1 Parent(s): a0a9509

Add application file

Browse files
Files changed (1) hide show
  1. app.py +13 -25
app.py CHANGED
@@ -37,9 +37,6 @@ except Exception as e:
37
  st.error(f"DuckDB connection failed: {e}")
38
  st.stop()
39
 
40
- # Enable full-text search index on first run (one-time setup if not exists)
41
- con.execute("PRAGMA create_fts_index('data', 'text')")
42
-
43
  # Search
44
  query = st.text_input("Search text (case-insensitive)", "").strip()
45
 
@@ -47,10 +44,10 @@ if query:
47
  sql = """
48
  SELECT id, channel, video_id, video_title, speaker, start_time, end_time, text, pos_tags, upload_date, audio
49
  FROM data
50
- WHERE text % ?
51
  LIMIT 100
52
  """
53
- df = con.execute(sql, [query]).df()
54
  else:
55
  df = con.execute("""
56
  SELECT id, channel, video_id, video_title, speaker, start_time, end_time, text, pos_tags, upload_date, audio
@@ -79,26 +76,17 @@ else:
79
  return None
80
 
81
  df["audio_file"] = df["audio"].apply(render_audio_cell)
82
- df_display = df.drop(columns=["audio"]).copy()
83
-
84
- # Add HTML audio tag column
85
- def audio_html(path):
86
- if path:
87
- return f'<audio controls preload="none" style="height:20px;"> <source src="file://{path}" type="audio/mpeg"> </audio>'
88
- return ""
89
-
90
- df_display["Audio"] = df["audio_file"].apply(audio_html)
91
 
92
- # Reorder columns
93
- column_order = ["id", "channel", "video_id", "video_title", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags", "Audio"]
94
- df_display = df_display[column_order]
95
-
96
- st.markdown("### Full Table View (Sortable)")
97
- st.write("Note: Audio is embedded using HTML tags; not all browsers allow playback from local temp paths.")
98
- st.dataframe(df_display.drop(columns=["Audio"]))
99
 
 
100
  st.markdown("### Audio Previews")
101
- for i, row in df_display.iterrows():
102
- if row["Audio"]:
103
- st.markdown(f"**{row['speaker']} | {row['text'][:80]}**", unsafe_allow_html=True)
104
- st.markdown(row["Audio"], unsafe_allow_html=True)
 
 
 
 
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
 
 
44
  sql = """
45
  SELECT id, channel, video_id, video_title, speaker, start_time, end_time, text, pos_tags, upload_date, audio
46
  FROM data
47
+ WHERE LOWER(text) LIKE LOWER(?)
48
  LIMIT 100
49
  """
50
+ df = con.execute(sql, [f"%{query}%"]).df()
51
  else:
52
  df = con.execute("""
53
  SELECT id, channel, video_id, video_title, speaker, start_time, end_time, text, pos_tags, upload_date, audio
 
76
  return None
77
 
78
  df["audio_file"] = df["audio"].apply(render_audio_cell)
 
 
 
 
 
 
 
 
 
79
 
80
+ # Display table (sortable)
81
+ df_display = df[["id", "channel", "video_id", "video_title", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags"]].copy()
82
+ st.dataframe(df_display, use_container_width=True)
 
 
 
 
83
 
84
+ # Audio previews column (aligned separately)
85
  st.markdown("### Audio Previews")
86
+ for i, row in df.iterrows():
87
+ audio_path = row["audio_file"]
88
+ if audio_path:
89
+ st.audio(audio_path, format="audio/mp3")
90
+ else:
91
+ st.warning("Missing or unreadable audio.")
92
+