EnariGmbH commited on
Commit
623c6f2
1 Parent(s): 20c305b

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +15 -1
handler.py CHANGED
@@ -2,6 +2,13 @@ from typing import Dict, List, Any
2
  import torch
3
  from transformers import LlavaNextVideoForConditionalGeneration, LlavaNextVideoProcessor
4
  from peft import PeftModel
 
 
 
 
 
 
 
5
 
6
  class EndpointHandler:
7
  def __init__(self):
@@ -39,7 +46,14 @@ class EndpointHandler:
39
  List[Dict[str, Any]]: The generated text from the model.
40
  """
41
  # Extract inputs from the data dictionary
42
- clip = data.get("clip")
 
 
 
 
 
 
 
43
 
44
  prompt = """
45
  You are a surfing coach specialized on perfecting surfer's pop-up move. Please analyze the surfer's pop-up move in detail from the video.
 
2
  import torch
3
  from transformers import LlavaNextVideoForConditionalGeneration, LlavaNextVideoProcessor
4
  from peft import PeftModel
5
+ import base64
6
+ import numpy as np
7
+
8
+ def base64_to_numpy(base64_str, shape):
9
+ arr_bytes = base64.b64decode(base64_str)
10
+ arr = np.frombuffer(arr_bytes, dtype=np.uint8)
11
+ return arr.reshape(shape)
12
 
13
  class EndpointHandler:
14
  def __init__(self):
 
46
  List[Dict[str, Any]]: The generated text from the model.
47
  """
48
  # Extract inputs from the data dictionary
49
+ clip_base64 = data.get("clip")
50
+ clip_shape = data.get("clip_shape") # Expect the shape to be passed
51
+
52
+ if clip_base64 is None or clip_shape is None:
53
+ return [{"error": "Missing 'clip' or 'clip_shape' in input data"}]
54
+
55
+ # Decode the base64 back to numpy array and reshape
56
+ clip = base64_to_numpy(clip_base64, tuple(clip_shape))
57
 
58
  prompt = """
59
  You are a surfing coach specialized on perfecting surfer's pop-up move. Please analyze the surfer's pop-up move in detail from the video.