stcoats commited on
Commit
7974c3c
·
1 Parent(s): 6763ad1

Add application file

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -38,19 +38,17 @@ except Exception as 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
- search_terms = query.lower().split()
46
- conditions = " AND ".join(["LOWER(text) LIKE ?" for _ in search_terms])
47
- sql = f"""
48
  SELECT id, channel, video_id, speaker, start_time, end_time, upload_date, text, pos_tags, audio
49
  FROM data
50
- WHERE {conditions}
51
  LIMIT 100
52
  """
53
- df = con.execute(sql, [f"%{term}%" for term in search_terms]).df()
54
  else:
55
  df = con.execute("""
56
  SELECT id, channel, video_id, speaker, start_time, end_time, upload_date, text, pos_tags, audio
@@ -74,7 +72,7 @@ else:
74
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
75
  tmp.write(data)
76
  tmp.flush()
77
- return f'<audio controls style="height:20px;width:100%;"><source src="file://{tmp.name}" type="audio/mpeg"></audio>'
78
  except Exception:
79
  return ""
80
 
@@ -82,17 +80,24 @@ else:
82
  df = df.drop(columns=["audio"])
83
  df = df[["id", "channel", "video_id", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags", "Audio"]]
84
 
85
- from st_aggrid import AgGrid, GridOptionsBuilder
86
 
87
- st.markdown("### Results Table (Sortable with Embedded Audio)")
88
 
89
- gb = GridOptionsBuilder.from_dataframe(df.drop(columns=["Audio"]))
90
- gb.configure_default_column(resizable=True, sortable=True, filter=True)
91
- grid_options = gb.build()
 
 
 
92
 
93
- AgGrid(df.drop(columns=["Audio"]), gridOptions=grid_options, fit_columns_on_grid_load=True)
 
 
 
 
94
 
95
- st.markdown("### Audio Controls in Table")
96
- for i in range(len(df)):
97
- st.markdown(df.loc[i, "Audio"], unsafe_allow_html=True)
98
 
 
 
38
  st.stop()
39
 
40
  # Search input
41
+ query = st.text_input("Search text (case-insensitive, exact substring match)", "").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
 
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
 
 
80
  df = df.drop(columns=["audio"])
81
  df = df[["id", "channel", "video_id", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags", "Audio"]]
82
 
83
+ st.markdown("### Results Table (Sortable with Audio Column)")
84
 
85
+ from streamlit.components.v1 import html
86
 
87
+ def generate_table_with_audio(df):
88
+ table_html = "<table border='1' style='border-collapse: collapse; width:100%; font-size:13px;'>"
89
+ table_html += "<thead><tr>"
90
+ for col in df.columns:
91
+ table_html += f"<th>{col}</th>"
92
+ table_html += "</tr></thead><tbody>"
93
 
94
+ for _, row in df.iterrows():
95
+ table_html += "<tr>"
96
+ for col in df.columns:
97
+ table_html += f"<td>{row[col]}</td>"
98
+ table_html += "</tr>"
99
 
100
+ table_html += "</tbody></table>"
101
+ return table_html
 
102
 
103
+ html(generate_table_with_audio(df), height=600, scrolling=True)