-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathdata.audio_column.py
More file actions
48 lines (37 loc) · 1.22 KB
/
data.audio_column.py
File metadata and controls
48 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import base64
import pandas as pd
import streamlit as st
@st.cache_data
def load_audio_as_base64():
with open("python/api-examples-source/cat-purr.mp3", "rb") as audio_file:
audio_bytes = audio_file.read()
return base64.b64encode(audio_bytes).decode("utf-8")
data_df = pd.DataFrame(
{
"source": [
"Small and fluffy house panther",
"Wikimedia, Performed by Muriel Nguyen Xuan and Stéphane Magnenat",
],
"audio": [
f"data:audio/mp3;base64,{load_audio_as_base64()}",
"https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg",
],
}
)
st.dataframe(
data_df,
column_config={
"audio": st.column_config.AudioColumn("Preview Audio"),
},
)
st.caption(
"""
##### Audio credit:
Performer: _Muriel Nguyen Xuan_ and _Stéphane Magnenat_
Composer: Frédéric Chopin
License: Creative Commons Attribution-Share Alike 4.0 International, 3.0 Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic license.
https://creativecommons.org/licenses/by-sa/4.0/
URL:
https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg
"""
)