hypaai commited on
Commit
57df8d3
·
verified ·
1 Parent(s): 4805443

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +1 -76
handler.py CHANGED
@@ -19,81 +19,6 @@ rather than the custom audio generation handler you've defined.
19
  Create a `handler.py` file with your custom handler code:
20
  """
21
 
22
- # import torch
23
- # import numpy as np
24
-
25
- # from transformers import AutoModelForCausalLM, AutoTokenizer
26
-
27
- # class EndpointHandler():
28
- # def __init__(self, path=""):
29
-
30
- # # Load the models and tokenizer
31
- # self.model = AutoModelForCausalLM.from_pretrained(
32
- # "hypaai/Hypa_Orpheus-3b-0.1-ft-unsloth-merged_16bit",
33
- # torch_dtype=torch.bfloat16
34
- # )
35
- # self.tokenizer = AutoTokenizer.from_pretrained("hypaai/Hypa_Orpheus-3b-0.1-ft-unsloth-merged_16bit")
36
-
37
- # # Move to devices
38
- # self.device = "cuda" if torch.cuda.is_available() else "cpu"
39
- # self.model.to(self.device)
40
-
41
- # # Special tokens
42
- # self.start_token = torch.tensor([[128259]], dtype=torch.int64) # Start of human
43
- # self.end_tokens = torch.tensor([[128009, 128260]], dtype=torch.int64) # End of text, End of human
44
- # self.padding_token = 128263
45
- # self.start_audio_token = 128257 # Start of Audio token
46
- # self.end_audio_token = 128258 # End of Audio token
47
-
48
-
49
- # def __call__(self, data):
50
- # """
51
- # Main entry point for the handler
52
- # """
53
-
54
- # # Preprocess input
55
- # if isinstance(data, dict) and "inputs" in data:
56
- # text = data["inputs"]
57
- # parameters = data.get("parameters", {})
58
- # else:
59
- # text = data
60
- # parameters = {}
61
-
62
- # # Extract parameters from request
63
- # voice = parameters.get("voice", "tara")
64
- # temperature = float(parameters.get("temperature", 0.6))
65
- # top_p = float(parameters.get("top_p", 0.95))
66
- # max_new_tokens = int(parameters.get("max_new_tokens", 1200))
67
- # repetition_penalty = float(parameters.get("repetition_penalty", 1.1))
68
-
69
- # # Format prompt with voice
70
- # prompt = f"{voice}: {text}"
71
-
72
- # # Tokenize
73
- # input_ids = self.tokenizer(prompt, return_tensors="pt").input_ids
74
-
75
- # # Add special tokens
76
- # modified_input_ids = torch.cat([self.start_token, input_ids, self.end_tokens], dim=1)
77
-
78
- # # No need for padding as we're processing a single sequence
79
- # input_ids = modified_input_ids.to(self.device)
80
- # attention_mask = torch.ones_like(input_ids)
81
-
82
- # # Forward pass through the model
83
- # generated_ids = self.model.generate(
84
- # input_ids=input_ids,
85
- # attention_mask=attention_mask,
86
- # max_new_tokens=max_new_tokens,
87
- # do_sample=True,
88
- # temperature=temperature,
89
- # top_p=top_p,
90
- # repetition_penalty=repetition_penalty,
91
- # num_return_sequences=1,
92
- # eos_token_id=self.end_audio_token,
93
- # )
94
-
95
- # return generated_ids
96
- # Code from your original handler, but with some fixes
97
  import os
98
  import torch
99
  import numpy as np
@@ -305,7 +230,7 @@ class EndpointHandler:
305
  logger.info(f"Audio encoded as base64, length: {len(audio_b64)}")
306
 
307
  return {
308
- "generated_ids": generated_ids.tolist(), #OOO 05102025
309
  "audio_b64": audio_b64,
310
  "sample_rate": 24000
311
  }
 
19
  Create a `handler.py` file with your custom handler code:
20
  """
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  import os
23
  import torch
24
  import numpy as np
 
230
  logger.info(f"Audio encoded as base64, length: {len(audio_b64)}")
231
 
232
  return {
233
+ "audio_sample": audio_sample,
234
  "audio_b64": audio_b64,
235
  "sample_rate": 24000
236
  }