Spaces:
Running
on
T4
Running
on
T4
Hervé Bredin
commited on
Commit
•
56a16bc
1
Parent(s):
c174364
feat: add code sample
Browse files
app.py
CHANGED
@@ -56,13 +56,8 @@ st.set_page_config(
|
|
56 |
|
57 |
st.sidebar.image(PYANNOTE_LOGO)
|
58 |
|
59 |
-
st.markdown(
|
60 |
-
|
61 |
-
# 🎹 Pretrained pipelines
|
62 |
-
|
63 |
-
Upload an audio file and the first {EXCERPT:g} seconds will be processed automatically.
|
64 |
-
"""
|
65 |
-
)
|
66 |
|
67 |
PIPELINES = [
|
68 |
p.modelId
|
@@ -72,12 +67,12 @@ PIPELINES = [
|
|
72 |
|
73 |
audio = Audio(sample_rate=16000, mono=True)
|
74 |
|
75 |
-
selected_pipeline = st.selectbox("", PIPELINES, index=0)
|
76 |
|
77 |
with st.spinner("Loading pipeline..."):
|
78 |
pipeline = Pipeline.from_pretrained(selected_pipeline)
|
79 |
|
80 |
-
uploaded_file = st.file_uploader("")
|
81 |
if uploaded_file is not None:
|
82 |
|
83 |
try:
|
@@ -90,7 +85,7 @@ if uploaded_file is not None:
|
|
90 |
)
|
91 |
file = {"waveform": waveform, "sample_rate": sample_rate, "uri": uploaded_file.name}
|
92 |
|
93 |
-
with st.spinner("
|
94 |
output = pipeline(file)
|
95 |
|
96 |
with open('assets/template.html') as html, open('assets/style.css') as css:
|
@@ -123,17 +118,27 @@ if uploaded_file is not None:
|
|
123 |
labels.append(label)
|
124 |
|
125 |
html = html_template.replace("BASE64", BASE64).replace("REGIONS", REGIONS)
|
126 |
-
st.markdown("<div style='overflow : auto'><ul class='legend'>"+LEGENDS+"</ul></div>", unsafe_allow_html=True)
|
127 |
components.html(html, height=250, scrolling=True)
|
|
|
|
|
|
|
128 |
|
129 |
with io.StringIO() as fp:
|
130 |
output.write_rttm(fp)
|
131 |
content = fp.getvalue()
|
132 |
|
133 |
b64 = base64.b64encode(content.encode()).decode()
|
134 |
-
href = f'<a download="{output.uri}.rttm" href="data:file/text;base64,{b64}">
|
135 |
st.markdown(href, unsafe_allow_html=True)
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
st.sidebar.markdown(
|
139 |
"""
|
|
|
56 |
|
57 |
st.sidebar.image(PYANNOTE_LOGO)
|
58 |
|
59 |
+
st.markdown("""# 🎹 Pretrained pipelines
|
60 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
PIPELINES = [
|
63 |
p.modelId
|
|
|
67 |
|
68 |
audio = Audio(sample_rate=16000, mono=True)
|
69 |
|
70 |
+
selected_pipeline = st.selectbox("Select a pipeline", PIPELINES, index=0)
|
71 |
|
72 |
with st.spinner("Loading pipeline..."):
|
73 |
pipeline = Pipeline.from_pretrained(selected_pipeline)
|
74 |
|
75 |
+
uploaded_file = st.file_uploader("Choose an audio file")
|
76 |
if uploaded_file is not None:
|
77 |
|
78 |
try:
|
|
|
85 |
)
|
86 |
file = {"waveform": waveform, "sample_rate": sample_rate, "uri": uploaded_file.name}
|
87 |
|
88 |
+
with st.spinner(f"Processing first {EXCERPT:g} seconds..."):
|
89 |
output = pipeline(file)
|
90 |
|
91 |
with open('assets/template.html') as html, open('assets/style.css') as css:
|
|
|
118 |
labels.append(label)
|
119 |
|
120 |
html = html_template.replace("BASE64", BASE64).replace("REGIONS", REGIONS)
|
|
|
121 |
components.html(html, height=250, scrolling=True)
|
122 |
+
st.markdown("<div style='overflow : auto'><ul class='legend'>"+LEGENDS+"</ul></div>", unsafe_allow_html=True)
|
123 |
+
|
124 |
+
st.markdown("---")
|
125 |
|
126 |
with io.StringIO() as fp:
|
127 |
output.write_rttm(fp)
|
128 |
content = fp.getvalue()
|
129 |
|
130 |
b64 = base64.b64encode(content.encode()).decode()
|
131 |
+
href = f'Download as <a download="{output.uri}.rttm" href="data:file/text;base64,{b64}">RTTM</a> or run it on the whole {int(duration):d}s file:'
|
132 |
st.markdown(href, unsafe_allow_html=True)
|
133 |
|
134 |
+
code = f"""
|
135 |
+
from pyannote.audio import Pipeline
|
136 |
+
pipeline = Pipeline.from_pretrained("{selected_pipeline}")
|
137 |
+
output = pipeline("{uploaded_file.name}")
|
138 |
+
"""
|
139 |
+
st.code(code, language='python')
|
140 |
+
|
141 |
+
|
142 |
|
143 |
st.sidebar.markdown(
|
144 |
"""
|