ariG23498 HF Staff commited on
Commit
ff20578
·
verified ·
1 Parent(s): 6a8dc0f

Upload pyannote_segmentation-3.0_1.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pyannote_segmentation-3.0_1.py +74 -0
pyannote_segmentation-3.0_1.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "numpy",
5
+ # "einops",
6
+ # "pandas",
7
+ # "matplotlib",
8
+ # "protobuf",
9
+ # "torch",
10
+ # "sentencepiece",
11
+ # "torchvision",
12
+ # "transformers",
13
+ # "timm",
14
+ # "diffusers",
15
+ # "sentence-transformers",
16
+ # "accelerate",
17
+ # "peft",
18
+ # "slack-sdk",
19
+ # ]
20
+ # ///
21
+
22
+ try:
23
+ from pyannote.audio import Model, Inference
24
+
25
+ model = Model.from_pretrained("pyannote/segmentation-3.0")
26
+ inference = Inference(model)
27
+
28
+ # inference on the whole file
29
+ inference("file.wav")
30
+
31
+ # inference on an excerpt
32
+ from pyannote.core import Segment
33
+ excerpt = Segment(start=2.0, end=5.0)
34
+ inference.crop("file.wav", excerpt)
35
+ with open('pyannote_segmentation-3.0_1.txt', 'w', encoding='utf-8') as f:
36
+ f.write('Everything was good in pyannote_segmentation-3.0_1.txt')
37
+ except Exception as e:
38
+ import os
39
+ from slack_sdk import WebClient
40
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
41
+ client.chat_postMessage(
42
+ channel='#hub-model-metadata-snippets-sprint',
43
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/pyannote_segmentation-3.0_1.txt|pyannote_segmentation-3.0_1.txt>',
44
+ )
45
+
46
+ with open('pyannote_segmentation-3.0_1.txt', 'a', encoding='utf-8') as f:
47
+ import traceback
48
+ f.write('''```CODE:
49
+ from pyannote.audio import Model, Inference
50
+
51
+ model = Model.from_pretrained("pyannote/segmentation-3.0")
52
+ inference = Inference(model)
53
+
54
+ # inference on the whole file
55
+ inference("file.wav")
56
+
57
+ # inference on an excerpt
58
+ from pyannote.core import Segment
59
+ excerpt = Segment(start=2.0, end=5.0)
60
+ inference.crop("file.wav", excerpt)
61
+ ```
62
+
63
+ ERROR:
64
+ ''')
65
+ traceback.print_exc(file=f)
66
+
67
+ finally:
68
+ from huggingface_hub import upload_file
69
+ upload_file(
70
+ path_or_fileobj='pyannote_segmentation-3.0_1.txt',
71
+ repo_id='model-metadata/code_execution_files',
72
+ path_in_repo='pyannote_segmentation-3.0_1.txt',
73
+ repo_type='dataset',
74
+ )