Dan commited on
Commit
c21da3a
·
1 Parent(s): e4f521b

register pipeline

Browse files
.gitignore CHANGED
@@ -1 +1,2 @@
1
  .vscode
 
 
1
  .vscode
2
+ __pycache__
README.md CHANGED
@@ -55,3 +55,33 @@ Here are some results:
55
  <source src="https://huggingface.co/cubbk/orpheus-swedish/resolve/main/audios/6.wav" type="audio/wav">
56
  Your browser does not support the audio element.
57
  </audio>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  <source src="https://huggingface.co/cubbk/orpheus-swedish/resolve/main/audios/6.wav" type="audio/wav">
56
  Your browser does not support the audio element.
57
  </audio>
58
+
59
+ ## How to use
60
+
61
+ ```
62
+ %pip install transformers snac soundfile torch torchaudio
63
+ ```
64
+
65
+ ```py
66
+ from transformers import pipeline
67
+
68
+ # Use your custom task name and model repo id
69
+ pipe = pipeline(task="orpheus-swedish", model="cubbk/orpheus-swedish", trust_remote_code=True)
70
+ ```
71
+
72
+ ```py
73
+ from IPython.display import Audio, display
74
+
75
+ prompt = [
76
+ "Enligt brittiska medier kommer ledarna att presentera en techpakt som ska stärka ländernas samarbete kring AI, kvantfysik och kärnkraft."
77
+ ]
78
+ outputs = pipe(prompt)
79
+
80
+ for i in range(len(outputs)):
81
+ print(prompt[i])
82
+ samples = outputs[i][0]
83
+ display(Audio(samples.detach().squeeze().to("cpu").numpy(), rate=24000))
84
+ ```
85
+
86
+ Good to know: performs poorly on short text
87
+ Cuts out at 14 sec.(didn't figure out why)
pipeline/pipeline.py CHANGED
@@ -6,7 +6,7 @@ from huggingface_hub import snapshot_download
6
 
7
 
8
  class MyPipeline(Pipeline):
9
- def __init__(self):
10
  self.snac_model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz")
11
  self.snac_model = self.snac_model.to("cpu")
12
  print(
@@ -41,7 +41,11 @@ class MyPipeline(Pipeline):
41
  self.model = AutoModelForCausalLM.from_pretrained(
42
  model_name, torch_dtype=torch.bfloat16
43
  )
44
- self.model.cuda()
 
 
 
 
45
  self.tokenizer = AutoTokenizer.from_pretrained(model_name)
46
 
47
  super().__init__(model=self.model, tokenizer=self.tokenizer)
 
6
 
7
 
8
  class MyPipeline(Pipeline):
9
+ def __init__(self, model=None, tokenizer=None, feature_extractor=None, **kwargs):
10
  self.snac_model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz")
11
  self.snac_model = self.snac_model.to("cpu")
12
  print(
 
41
  self.model = AutoModelForCausalLM.from_pretrained(
42
  model_name, torch_dtype=torch.bfloat16
43
  )
44
+ if torch.cuda.is_available():
45
+ self.model = self.model.cuda()
46
+ else:
47
+ print("CUDA not available, running on CPU.")
48
+
49
  self.tokenizer = AutoTokenizer.from_pretrained(model_name)
50
 
51
  super().__init__(model=self.model, tokenizer=self.tokenizer)
pipeline/register_pipeline.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .pipeline import MyPipeline
2
+ from transformers.pipelines import PIPELINE_REGISTRY
3
+ from transformers import AutoModelForCausalLM, pipeline as hf_pipeline
4
+
5
+ # Register your custom pipeline under a custom task name
6
+ PIPELINE_REGISTRY.register_pipeline(
7
+ "orpheus-swedish", # custom task name
8
+ pipeline_class=MyPipeline,
9
+ pt_model=AutoModelForCausalLM,
10
+ )
11
+
12
+ # Instantiate your pipeline using the custom task name and your model repo id
13
+ my_pipe = hf_pipeline(task="orpheus-swedish", model="cubbk/orpheus-swedish")
14
+ my_pipe.push_to_hub("cubbk/orpheus-swedish")
pipeline/test_deployed_pipeline.ipynb ADDED
The diff for this file is too large to render. See raw diff