sitammeur commited on
Commit
4ba4f88
·
verified ·
1 Parent(s): dc1e050

Update src/model.py

Browse files
Files changed (1) hide show
  1. src/model.py +20 -1
src/model.py CHANGED
@@ -22,6 +22,24 @@ tokenizer = AutoTokenizer.from_pretrained(
22
  model.eval()
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  @spaces.GPU()
26
  def describe_video(video, question):
27
  """
@@ -35,7 +53,8 @@ def describe_video(video, question):
35
  str: The generated answer to the question.
36
  """
37
  # Encode the video frames
38
- frames = encode_video(video)
 
39
  #frames = list(frames) # Convert generator or any iterable to list
40
 
41
  # Message format for the model
 
22
  model.eval()
23
 
24
 
25
+ class _GeneratorPickleHack:
26
+ def __init__(self, generator, generator_id=None):
27
+ self.generator = generator
28
+ self.generator_id = (
29
+ generator_id if generator_id is not None else str(uuid.uuid4())
30
+ )
31
+
32
+ def __call__(self, *args, **kwargs):
33
+ return self.generator(*args, **kwargs)
34
+
35
+ def __reduce__(self):
36
+ return (_GeneratorPickleHack_raise, (self.generator_id,))
37
+
38
+
39
+ def _GeneratorPickleHack_raise(*args, **kwargs):
40
+ raise AssertionError("cannot actually unpickle _GeneratorPickleHack!")
41
+
42
+
43
  @spaces.GPU()
44
  def describe_video(video, question):
45
  """
 
53
  str: The generated answer to the question.
54
  """
55
  # Encode the video frames
56
+ frames = _GeneratorPickleHack(encode_video)(video)
57
+ #frames = encode_video(video)
58
  #frames = list(frames) # Convert generator or any iterable to list
59
 
60
  # Message format for the model