Spaces:
Sleeping
Sleeping
Add: CoNeTTE streamlit application for inference on files.
Browse files
app.py
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
|
| 4 |
+
from tempfile import NamedTemporaryFile
|
| 5 |
+
|
| 6 |
import streamlit as st
|
| 7 |
|
| 8 |
+
from conette import CoNeTTEModel, conette
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def load_conette(*args, **kwargs) -> CoNeTTEModel:
|
| 13 |
+
return conette(*args, **kwargs)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def main() -> None:
|
| 17 |
+
st.header("CoNeTTE model test")
|
| 18 |
+
audios = st.file_uploader(
|
| 19 |
+
"Upload an audio file",
|
| 20 |
+
type=["wav", "flac", "mp3", "ogg", "avi"],
|
| 21 |
+
accept_multiple_files=True,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
if audios is not None and len(audios) > 0:
|
| 25 |
+
model = load_conette(model_kwds=dict(device="cpu"))
|
| 26 |
+
|
| 27 |
+
for audio in audios:
|
| 28 |
+
with NamedTemporaryFile() as temp:
|
| 29 |
+
temp.write(audio.getvalue())
|
| 30 |
+
fpath = temp.name
|
| 31 |
+
outputs = model(fpath)
|
| 32 |
+
cand = outputs["cands"][0]
|
| 33 |
+
|
| 34 |
+
st.write(f"Output for {audio.name}:")
|
| 35 |
+
st.write(" - ", cand)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
main()
|