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

Add application file

Browse files
Files changed (1) hide show
  1. app.py +28 -17
app.py CHANGED
@@ -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_html(audio_bytes):
65
  try:
66
  if isinstance(audio_bytes, (bytes, bytearray, memoryview)):
67
  data = bytes(audio_bytes)
@@ -72,32 +72,43 @@ 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_html)
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)
 
 
 
61
  if len(df) == 0:
62
  st.warning("No matches found.")
63
  else:
64
+ def render_audio_tag(audio_bytes, index):
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 preload="metadata" style="height:20px;width:100px;"><source src="file://{tmp.name}" type="audio/mpeg"></audio>'
76
  except Exception:
77
  return ""
78
 
79
+ df["audio_player"] = [render_audio_tag(b, i) for i, b in enumerate(df["audio"])]
80
+ df_display = df.drop(columns=["audio"])
 
 
 
81
 
82
  from streamlit.components.v1 import html
83
 
84
+ def display_html_table(df):
85
+ table_html = """
86
+ <table border='1' style='border-collapse:collapse;width:100%;font-size:13px;'>
87
+ <thead>
88
+ <tr>
89
+ <th style='width:8em;'>id</th>
90
+ <th>channel</th>
91
+ <th>video_id</th>
92
+ <th>speaker</th>
93
+ <th>start_time</th>
94
+ <th>end_time</th>
95
+ <th>upload_date</th>
96
+ <th>text</th>
97
+ <th>pos_tags</th>
98
+ <th>audio</th>
99
+ </tr>
100
+ </thead>
101
+ <tbody>
102
+ """
103
  for _, row in df.iterrows():
104
  table_html += "<tr>"
105
+ for col in ["id", "channel", "video_id", "speaker", "start_time", "end_time", "upload_date", "text", "pos_tags"]:
106
  table_html += f"<td>{row[col]}</td>"
107
+ table_html += f"<td>{row['audio_player']}</td>"
108
  table_html += "</tr>"
 
109
  table_html += "</tbody></table>"
110
  return table_html
111
 
112
+ st.markdown("### Results Table (Sortable with Audio Column)")
113
+ html(display_html_table(df_display), height=800, scrolling=True)
114
+