Spaces:
Sleeping
Sleeping
Hervé Bredin
commited on
Commit
•
ebc74bd
0
Parent(s):
feat: initial import
Browse files- .github/workflows/check_size.yaml +17 -0
- .github/workflows/sync_to_hub.yaml +20 -0
- README.md +37 -0
- app.py +87 -0
- packages.txt +1 -0
- requirements.txt +4 -0
.github/workflows/check_size.yaml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Check file size
|
2 |
+
|
3 |
+
on:
|
4 |
+
pull_request:
|
5 |
+
branches: [main]
|
6 |
+
|
7 |
+
# to run this workflow manually from the Actions tab
|
8 |
+
workflow_dispatch:
|
9 |
+
|
10 |
+
jobs:
|
11 |
+
sync-to-hub:
|
12 |
+
runs-on: ubuntu-latest
|
13 |
+
steps:
|
14 |
+
- name: Check large files
|
15 |
+
uses: ActionsDesk/[email protected]
|
16 |
+
with:
|
17 |
+
filesizelimit: 10485760 # = 10MB, so we can sync to HF spaces
|
.github/workflows/sync_to_hub.yaml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Sync to Hugging Face hub
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches: [main]
|
6 |
+
|
7 |
+
# to run this workflow manually from the Actions tab
|
8 |
+
workflow_dispatch:
|
9 |
+
|
10 |
+
jobs:
|
11 |
+
sync-to-hub:
|
12 |
+
runs-on: ubuntu-latest
|
13 |
+
steps:
|
14 |
+
- uses: actions/checkout@v2
|
15 |
+
with:
|
16 |
+
fetch-depth: 0
|
17 |
+
- name: Push to hub
|
18 |
+
env:
|
19 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
20 |
+
run: git push https://hbredin:[email protected]/spaces/pyannote/pretrained-pipelines main --force
|
README.md
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Pretrained pipelines
|
3 |
+
emoji: 🎹
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
+
sdk: streamlit
|
7 |
+
app_file: app.py
|
8 |
+
pinned: true
|
9 |
+
---
|
10 |
+
|
11 |
+
# Configuration
|
12 |
+
|
13 |
+
`title`: _string_
|
14 |
+
Display title for the Space
|
15 |
+
|
16 |
+
`emoji`: _string_
|
17 |
+
Space emoji (emoji-only character allowed)
|
18 |
+
|
19 |
+
`colorFrom`: _string_
|
20 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
21 |
+
|
22 |
+
`colorTo`: _string_
|
23 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
24 |
+
|
25 |
+
`sdk`: _string_
|
26 |
+
Can be either `gradio` or `streamlit`
|
27 |
+
|
28 |
+
`sdk_version` : _string_
|
29 |
+
Only applicable for `streamlit` SDK.
|
30 |
+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
31 |
+
|
32 |
+
`app_file`: _string_
|
33 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
34 |
+
Path is relative to the root of the repository.
|
35 |
+
|
36 |
+
`pinned`: _boolean_
|
37 |
+
Whether the Space stays on top of your list.
|
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import HfApi
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import streamlit as st
|
4 |
+
from pyannote.audio import Pipeline
|
5 |
+
from pyannote.audio import Audio
|
6 |
+
from pyannote.core import notebook, Segment
|
7 |
+
import io
|
8 |
+
import base64
|
9 |
+
|
10 |
+
from matplotlib.backends.backend_agg import RendererAgg
|
11 |
+
|
12 |
+
_lock = RendererAgg.lock
|
13 |
+
|
14 |
+
PYANNOTE_LOGO = "https://avatars.githubusercontent.com/u/7559051?s=400&v=4"
|
15 |
+
EXCERPT = 30.0
|
16 |
+
|
17 |
+
st.set_page_config(
|
18 |
+
page_title="pyannote.audio pretrained pipelines",
|
19 |
+
page_icon=PYANNOTE_LOGO)
|
20 |
+
|
21 |
+
st.sidebar.image(PYANNOTE_LOGO)
|
22 |
+
|
23 |
+
st.markdown(
|
24 |
+
f"""
|
25 |
+
# 🎹 Pretrained pipelines
|
26 |
+
|
27 |
+
Upload an audio file and the first {EXCERPT:g} seconds will be processed automatically.
|
28 |
+
"""
|
29 |
+
)
|
30 |
+
|
31 |
+
PIPELINES = [p.modelId for p in HfApi().list_models(filter="pyannote-audio-pipeline") if p.modelId.startswith("pyannote/")]
|
32 |
+
|
33 |
+
audio = Audio(sample_rate=16000, mono=True)
|
34 |
+
|
35 |
+
selected_pipeline = st.selectbox("", PIPELINES, index=0)
|
36 |
+
|
37 |
+
with st.spinner('Loading pipeline...'):
|
38 |
+
pipeline = Pipeline.from_pretrained(selected_pipeline)
|
39 |
+
|
40 |
+
uploaded_file = st.file_uploader("")
|
41 |
+
if uploaded_file is not None:
|
42 |
+
|
43 |
+
try:
|
44 |
+
duration = audio.get_duration(uploaded_file)
|
45 |
+
except RuntimeError as e:
|
46 |
+
st.error(e)
|
47 |
+
st.stop()
|
48 |
+
waveform, sample_rate = audio.crop(uploaded_file, Segment(0, min(duration, EXCERPT)))
|
49 |
+
file = {"waveform": waveform, "sample_rate": sample_rate, "uri": uploaded_file.name}
|
50 |
+
|
51 |
+
with st.spinner('Running pipeline...'):
|
52 |
+
output = pipeline(file)
|
53 |
+
|
54 |
+
with _lock:
|
55 |
+
|
56 |
+
notebook.reset()
|
57 |
+
notebook.crop = Segment(0, min(duration, EXCERPT))
|
58 |
+
|
59 |
+
fig, ax = plt.subplots(nrows=1, ncols=1)
|
60 |
+
fig.set_figwidth(12)
|
61 |
+
fig.set_figheight(2.0)
|
62 |
+
notebook.plot_annotation(output, ax=ax, time=True, legend=True)
|
63 |
+
|
64 |
+
plt.tight_layout()
|
65 |
+
st.pyplot(fig=fig, clear_figure=True)
|
66 |
+
plt.close(fig)
|
67 |
+
|
68 |
+
with io.StringIO() as fp:
|
69 |
+
output.write_rttm(fp)
|
70 |
+
content = fp.getvalue()
|
71 |
+
|
72 |
+
b64 = base64.b64encode(content.encode()).decode()
|
73 |
+
href = f'<a download="{output.uri}.rttm" href="data:file/text;base64,{b64}">Download as RTTM</a>'
|
74 |
+
st.markdown(href, unsafe_allow_html=True)
|
75 |
+
|
76 |
+
|
77 |
+
st.sidebar.markdown(
|
78 |
+
"""
|
79 |
+
-------------------
|
80 |
+
|
81 |
+
To use these pipelines on more and longer files on your own (GPU, hence much faster) servers, check the [documentation](https://github.com/pyannote/pyannote-audio).
|
82 |
+
|
83 |
+
For [technical questions](https://github.com/pyannote/pyannote-audio/discussions) and [bug reports](https://github.com/pyannote/pyannote-audio/issues), please check [pyannote.audio](https://github.com/pyannote/pyannote-audio) Github repository.
|
84 |
+
|
85 |
+
For commercial enquiries and scientific consulting, please contact [me](mailto:[email protected]).
|
86 |
+
"""
|
87 |
+
)
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
libsndfile1
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/pyannote/pyannote-audio.git@develop#egg=pyannote-audio
|
2 |
+
speechbrain == 0.5.10
|
3 |
+
matplotlib == 3.3.3
|
4 |
+
|