stcoats
commited on
Commit
·
a31425b
1
Parent(s):
1c7365b
Add application file
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import streamlit as st
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import pandas as pd
|
| 6 |
import tempfile
|
|
|
|
| 7 |
|
| 8 |
HF_REPO_ID = "stcoats/temp-duckdb-upload"
|
| 9 |
HF_FILENAME = "ycsep.duckdb"
|
|
@@ -19,32 +20,40 @@ if not os.path.exists(LOCAL_PATH):
|
|
| 19 |
repo_id=HF_REPO_ID,
|
| 20 |
repo_type="dataset",
|
| 21 |
filename=HF_FILENAME,
|
| 22 |
-
local_dir="."
|
|
|
|
| 23 |
)
|
| 24 |
st.success("Download complete.")
|
| 25 |
|
| 26 |
-
# Connect
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
-
con =
|
| 29 |
st.success("Connected to DuckDB.")
|
| 30 |
except Exception as e:
|
| 31 |
st.error(f"DuckDB connection failed: {e}")
|
| 32 |
st.stop()
|
| 33 |
|
| 34 |
# Search
|
| 35 |
-
query = st.text_input("Search text (case-insensitive)", "")
|
| 36 |
-
query = query.strip().lower()
|
| 37 |
|
| 38 |
if query:
|
| 39 |
sql = """
|
| 40 |
SELECT channel, file, speaker, start_time, end_time, text, pos_tags, audio
|
| 41 |
FROM data
|
| 42 |
-
WHERE LOWER(text) LIKE ?
|
| 43 |
LIMIT 100
|
| 44 |
"""
|
| 45 |
df = con.execute(sql, [f"%{query}%"]).df()
|
| 46 |
else:
|
| 47 |
-
df = con.execute("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
st.markdown(f"### Showing {len(df)} results")
|
| 50 |
|
|
@@ -53,13 +62,19 @@ if len(df) == 0:
|
|
| 53 |
|
| 54 |
# Show table with inline audio players
|
| 55 |
for i, row in df.iterrows():
|
| 56 |
-
col1, col2, col3 = st.columns([
|
| 57 |
-
|
| 58 |
-
col1.markdown(f"**
|
| 59 |
-
col1.markdown(f"**
|
| 60 |
-
col1.markdown(f"**
|
| 61 |
-
col1.markdown(f"**
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
col2.markdown(f"**POS tags:** {row['pos_tags']}")
|
| 64 |
|
| 65 |
audio_data = row["audio"]
|
|
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import pandas as pd
|
| 6 |
import tempfile
|
| 7 |
+
import re
|
| 8 |
|
| 9 |
HF_REPO_ID = "stcoats/temp-duckdb-upload"
|
| 10 |
HF_FILENAME = "ycsep.duckdb"
|
|
|
|
| 20 |
repo_id=HF_REPO_ID,
|
| 21 |
repo_type="dataset",
|
| 22 |
filename=HF_FILENAME,
|
| 23 |
+
local_dir=".",
|
| 24 |
+
local_dir_use_symlinks=False
|
| 25 |
)
|
| 26 |
st.success("Download complete.")
|
| 27 |
|
| 28 |
+
# Connect (only once)
|
| 29 |
+
@st.cache_resource(show_spinner=False)
|
| 30 |
+
def get_duckdb_connection():
|
| 31 |
+
return duckdb.connect(LOCAL_PATH, read_only=True)
|
| 32 |
+
|
| 33 |
try:
|
| 34 |
+
con = get_duckdb_connection()
|
| 35 |
st.success("Connected to DuckDB.")
|
| 36 |
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 |
sql = """
|
| 45 |
SELECT channel, file, speaker, start_time, end_time, text, pos_tags, 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 channel, file, speaker, start_time, end_time, text, pos_tags, audio
|
| 54 |
+
FROM data
|
| 55 |
+
LIMIT 100
|
| 56 |
+
""").df()
|
| 57 |
|
| 58 |
st.markdown(f"### Showing {len(df)} results")
|
| 59 |
|
|
|
|
| 62 |
|
| 63 |
# Show table with inline audio players
|
| 64 |
for i, row in df.iterrows():
|
| 65 |
+
col1, col2, col3 = st.columns([3, 5, 2])
|
| 66 |
+
|
| 67 |
+
col1.markdown(f"**Channel:** {row['channel']}")
|
| 68 |
+
col1.markdown(f"**File:** {row['file']}")
|
| 69 |
+
col1.markdown(f"**Speaker:** {row['speaker']}")
|
| 70 |
+
col1.markdown(f"**Start Time:** {row['start_time']}")
|
| 71 |
+
col1.markdown(f"**End Time:** {row['end_time']}")
|
| 72 |
+
|
| 73 |
+
highlighted_text = row['text']
|
| 74 |
+
if query:
|
| 75 |
+
highlighted_text = re.sub(f'({re.escape(query)})', r'<mark>\1</mark>', highlighted_text, flags=re.IGNORECASE)
|
| 76 |
+
|
| 77 |
+
col2.markdown(f"**Text:** {highlighted_text}", unsafe_allow_html=True)
|
| 78 |
col2.markdown(f"**POS tags:** {row['pos_tags']}")
|
| 79 |
|
| 80 |
audio_data = row["audio"]
|