File tree 3 files changed +28
-2
lines changed
3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 24
24
MAX_RANGE_SIZE , MIN_CHUNK_SIZE , MIN_RANGE_SIZE ,
25
25
MODEL_EXPORT_TIMEOUT , RANGE_SIZE , TRAINABLE_MODEL_TYPES )
26
26
from clarifai .errors import UserError
27
+ from clarifai .runners .utils import video_utils
27
28
from clarifai .urls .helper import ClarifaiUrlHelper
28
29
from clarifai .utils .logging import logger
29
30
from clarifai .utils .misc import BackoffIterator
@@ -1204,7 +1205,6 @@ def stream_by_video_file(self,
1204
1205
# by getting the original start time ffprobe and either sending that to the model so it can adjust
1205
1206
# with the ts of the first frame (too fragile to do all of this adjustment in the client input stream)
1206
1207
# or by adjusting the timestamps in the output stream
1207
- from clarifai .runners .utils import video_utils
1208
1208
stream = video_utils .convert_to_streamable (filepath )
1209
1209
1210
1210
# TODO accumulate reads to fill the chunk size
Original file line number Diff line number Diff line change 3
3
import tempfile
4
4
import threading
5
5
6
- import av
7
6
import requests
8
7
9
8
from clarifai .runners .utils import stream_utils
9
+ from clarifai .utils .misc import optional_import
10
+
11
+ av = optional_import ("av" , pip_package = "av" )
10
12
11
13
12
14
def stream_frames_from_url (url , download_ok = True ):
Original file line number Diff line number Diff line change
1
+ import importlib
1
2
import os
2
3
import re
3
4
import uuid
6
7
from clarifai .errors import UserError
7
8
8
9
10
+ def optional_import (module_name : str , pip_package : str = None ):
11
+ """Import a module if it exists.
12
+ Otherwise, return an object that will raise an error when accessed.
13
+ """
14
+ try :
15
+ return importlib .import_module (module_name )
16
+ except ImportError :
17
+ return _MissingModule (module_name , pip_package = pip_package )
18
+
19
+
20
+ class _MissingModule :
21
+ """Object that raises an error when accessed."""
22
+
23
+ def __init__ (self , module_name , pip_package = None ):
24
+ self .module_name = module_name
25
+ self .message = f"Module `{ module_name } ` is not installed."
26
+ if pip_package :
27
+ self .message += f" Please install it with `pip install { pip_package } `."
28
+
29
+ def __getattr__ (self , name ):
30
+ raise ImportError (self .message )
31
+
32
+
9
33
class Chunker :
10
34
"""Split an input sequence into small chunks."""
11
35
You can’t perform that action at this time.
0 commit comments