Hervé BREDIN commited on
Commit
b171431
1 Parent(s): 1c1581e

feat: display real-time factor

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -30,8 +30,10 @@ from typing import Text
30
  import streamlit as st
31
  from pyannote.audio import Pipeline
32
  from pyannote.audio import Audio
 
33
  from pyannote.core import Segment
34
 
 
35
  import streamlit.components.v1 as components
36
 
37
 
@@ -47,7 +49,7 @@ def to_base64(waveform: np.ndarray, sample_rate: int = 16000) -> Text:
47
 
48
 
49
  PYANNOTE_LOGO = "https://avatars.githubusercontent.com/u/7559051?s=400&v=4"
50
- EXCERPT = 120.0
51
 
52
  st.set_page_config(page_title="pyannote pretrained pipelines", page_icon=PYANNOTE_LOGO)
53
 
@@ -95,14 +97,28 @@ if uploaded_file is not None:
95
  except RuntimeError as e:
96
  st.error(e)
97
  st.stop()
98
- waveform, sample_rate = audio.crop(
99
- uploaded_file, Segment(0, min(duration, EXCERPT))
 
 
 
100
  )
 
 
 
101
  uri = "".join(uploaded_file.name.split())
102
  file = {"waveform": waveform, "sample_rate": sample_rate, "uri": uri}
103
 
104
- with st.spinner(f"Processing first {EXCERPT:g} seconds of the file..."):
105
- output = pipeline(file)
 
 
 
 
 
 
 
 
106
 
107
  with open("assets/template.html") as html, open("assets/style.css") as css:
108
  html_template = html.read()
 
30
  import streamlit as st
31
  from pyannote.audio import Pipeline
32
  from pyannote.audio import Audio
33
+ from pyannote.audio.pipelines.utils.hook import TimingHook
34
  from pyannote.core import Segment
35
 
36
+
37
  import streamlit.components.v1 as components
38
 
39
 
 
49
 
50
 
51
  PYANNOTE_LOGO = "https://avatars.githubusercontent.com/u/7559051?s=400&v=4"
52
+ EXCERPT = 120
53
 
54
  st.set_page_config(page_title="pyannote pretrained pipelines", page_icon=PYANNOTE_LOGO)
55
 
 
97
  except RuntimeError as e:
98
  st.error(e)
99
  st.stop()
100
+
101
+ spinner_message = (
102
+ f"Processing {duration:.0f}s file... "
103
+ if duration < EXCERPT
104
+ else f"Processing first {EXCERPT:.0f}s of file..."
105
  )
106
+
107
+ duration = min(duration, EXCERPT)
108
+ waveform, sample_rate = audio.crop(uploaded_file, Segment(0, duration))
109
  uri = "".join(uploaded_file.name.split())
110
  file = {"waveform": waveform, "sample_rate": sample_rate, "uri": uri}
111
 
112
+ with st.spinner(spinner_message):
113
+ with TimingHook() as hook:
114
+ output = pipeline(file, hook=hook)
115
+
116
+ processing_time = file["timing"]["total"]
117
+ faster_than_real_time = duration / processing_time
118
+ st.success(
119
+ f"Processed {duration:.0f}s of audio in {processing_time:.1f}s ({faster_than_real_time:.1f}x faster than real-time)",
120
+ icon="✅",
121
+ )
122
 
123
  with open("assets/template.html") as html, open("assets/style.css") as css:
124
  html_template = html.read()