stcoats
commited on
Commit
·
a47efdc
1
Parent(s):
5fde344
Add application file
Browse files
app.py
CHANGED
|
@@ -44,10 +44,10 @@ if query:
|
|
| 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, [
|
| 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
|
|
@@ -59,43 +59,44 @@ st.markdown(f"### Showing {len(df)} results")
|
|
| 59 |
|
| 60 |
if len(df) == 0:
|
| 61 |
st.warning("No matches found.")
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
| 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, [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
|
|
|
|
| 59 |
|
| 60 |
if len(df) == 0:
|
| 61 |
st.warning("No matches found.")
|
| 62 |
+
else:
|
| 63 |
+
def render_audio_cell(audio_bytes):
|
| 64 |
+
try:
|
| 65 |
+
if isinstance(audio_bytes, (bytes, bytearray, memoryview)):
|
| 66 |
+
data = bytes(audio_bytes)
|
| 67 |
+
elif isinstance(audio_bytes, list):
|
| 68 |
+
data = bytes(audio_bytes)
|
| 69 |
+
else:
|
| 70 |
+
return None
|
| 71 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
|
| 72 |
+
tmp.write(data)
|
| 73 |
+
tmp.flush()
|
| 74 |
+
return tmp.name
|
| 75 |
+
except Exception:
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
df["audio_file"] = df["audio"].apply(render_audio_cell)
|
| 79 |
+
|
| 80 |
+
# Build an interactive sortable table
|
| 81 |
+
st.markdown("### Results Table (Sortable)")
|
| 82 |
+
for i, row in df.iterrows():
|
| 83 |
+
with st.expander(f"? {row['speaker']} | {row['text'][:60]}..."):
|
| 84 |
+
col1, col2 = st.columns([2, 3])
|
| 85 |
+
|
| 86 |
+
with col1:
|
| 87 |
+
st.write(f"**ID:** {row['id']}")
|
| 88 |
+
st.write(f"**Channel:** {row['channel']}")
|
| 89 |
+
st.write(f"**Video ID:** {row['video_id']}")
|
| 90 |
+
st.write(f"**Video Title:** {row['video_title']}")
|
| 91 |
+
st.write(f"**Speaker:** {row['speaker']}")
|
| 92 |
+
st.write(f"**Start Time:** {row['start_time']}")
|
| 93 |
+
st.write(f"**End Time:** {row['end_time']}")
|
| 94 |
+
st.write(f"**Upload Date:** {row['upload_date']}")
|
| 95 |
+
st.write(f"**POS Tags:** {row['pos_tags']}")
|
| 96 |
+
|
| 97 |
+
with col2:
|
| 98 |
+
st.markdown(f"**Text:** {row['text']}")
|
| 99 |
+
if row['audio_file']:
|
| 100 |
+
st.audio(row['audio_file'], format="audio/mp3")
|
| 101 |
+
else:
|
| 102 |
+
st.warning("Audio not available or invalid format.")
|