benderrodriguez commited on
Commit
71c8e51
1 Parent(s): 23719bf

Different handler.

Browse files
Files changed (1) hide show
  1. handler.py +9 -20
handler.py CHANGED
@@ -10,26 +10,15 @@ 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
 
 
10
 
11
  def predict(audio_file_path):
12
  return 'Bender is great!'
13
+ class CustomHandler:
14
+ def __init__(self, model_name):
15
+ self.tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+ self.model = AutoModelForSequenceClassification.from_pretrained(model_name)
17
+ self.model.eval() # Set the model to evaluation mode
18
 
19
+ def __call__(self, data):
20
+ return 'Bender is great!'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ # Initialize the handler with your model
23
+ handler = CustomHandler(model_name)
24