benderrodriguez commited on
Commit
23719bf
1 Parent(s): 7c2f56b

New handler.

Browse files
Files changed (1) hide show
  1. handler.py +27 -20
handler.py CHANGED
@@ -1,28 +1,35 @@
1
  from typing import Dict, List, Any
2
  import faster_whisper
 
3
 
4
- class EndpointHandler():
5
- def __init__(self, path=""):
6
- self.model = faster_whisper.WhisperModel('ivrit-ai/faster-whisper-v2-d3-e3', device='cuda')
7
 
8
- def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
9
- """
10
- data args:
11
- inputs (:obj: `str`)
12
- date (:obj: `str`)
13
- Return:
14
- A :obj:`list` | `dict`: will be serialized and returned
15
- """
16
- # get inputs
17
- #inputs = data.pop("inputs",data)
18
- #date = data.pop("date", None)
19
 
20
- # check if date exists and if it is a holiday
21
- #if date is not None and date in self.holidays:
22
- # return [{"label": "happy", "score": 1}]
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- # run normal prediction
26
- #prediction = self.pipeline(inputs)
27
- return {'text' : 'bender is great!'}
28
 
 
1
  from typing import Dict, List, Any
2
  import faster_whisper
3
+ import torch
4
 
5
+ # Initialize the model and processor
6
+ model_name_or_path = "ivrit-ai/faster-whisper-v2-d3-e3"
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
+ model = faster_whisper.WhisperModel(model_name_or_path, device=device)
 
 
 
 
 
 
 
 
 
 
10
 
11
+ def predict(audio_file_path):
12
+ return 'Bender is great!'
 
13
 
14
+ def handler(event, context):
15
+ try:
16
+ # Parse input event
17
+ body = json.loads(event["body"])
18
+ audio_file_path = body["audio_file_path"]
19
+
20
+ # Run prediction
21
+ transcription = predict(audio_file_path)
22
+
23
+ # Create response
24
+ response = {
25
+ "statusCode": 200,
26
+ "body": json.dumps({"transcription": transcription})
27
+ }
28
+ except Exception as e:
29
+ response = {
30
+ "statusCode": 500,
31
+ "body": json.dumps({"error": str(e)})
32
+ }
33
 
34
+ return response
 
 
35