File size: 1,989 Bytes
a9b52e3 074b1c4 2153326 e208789 a9b52e3 e208789 2153326 e208789 2153326 e208789 2153326 a9b52e3 0d951c7 e208789 0d951c7 e208789 0d951c7 e208789 0d951c7 e208789 2153326 e208789 074b1c4 2153326 e208789 2153326 a9b52e3 |
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 49 50 51 52 53 54 55 56 57 |
import gradio as gr
from pyannote_viewer import PyannoteViewer
from pyannote.audio import Pipeline
import os
from huggingface_hub import HfApi
def apply_pipeline(audio: str, pipeline_name: str) -> tuple:
pipeline = Pipeline.from_pretrained(
pipeline_name, use_auth_token=os.environ["HF_TOKEN"]
)
outputs = pipeline(audio)
if isinstance(outputs, tuple):
return outputs
else:
return (outputs, audio)
with gr.Blocks() as demo:
# header
with gr.Row():
# pyannote logo
with gr.Column(scale=1):
gr.Markdown(
'<a href="https://github.com/pyannote/pyannote-audio"><img src="https://avatars.githubusercontent.com/u/7559051?s=200&v=4" alt="pyannote logo" width="170"/></a>'
)
# space title and description
with gr.Column(scale=10):
gr.Markdown('# pyannote pretrained pipelines')
gr.Markdown(
"You like [pyannote.audio](https://github.com/pyannote/pyannote-audio)? Consider using [pyannoteAI](https://pyannote.ai/) for better and faster options.\n"
"\nGo [here](https://huggingface.co/pyannote) for more detail on each pipeline available in this space."
)
gr.Markdown()
gr.Markdown("#### Select a pretrained pipeline:")
available_pipelines = [p.modelId for p in HfApi().list_models(filter="pyannote-audio-pipeline")]
available_pipelines = list(filter(lambda p: p.startswith("pyannote/"), available_pipelines))
dropdown = gr.Dropdown(choices=available_pipelines, value=available_pipelines[0], interactive=True, label="Pretrained pipeline")
gr.Markdown("#### Upload or record an audio:")
audio = gr.Audio(type="filepath")
btn = gr.Button("Apply pipeline")
source_viewer = PyannoteViewer(interactive=False)
btn.click(fn=apply_pipeline, inputs=[audio, dropdown], outputs=[source_viewer])
if __name__ == "__main__":
demo.launch()
|