File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 2424 MAX_RANGE_SIZE , MIN_CHUNK_SIZE , MIN_RANGE_SIZE ,
2525 MODEL_EXPORT_TIMEOUT , RANGE_SIZE , TRAINABLE_MODEL_TYPES )
2626from clarifai .errors import UserError
27+ from clarifai .runners .utils import video_utils
2728from clarifai .urls .helper import ClarifaiUrlHelper
2829from clarifai .utils .logging import logger
2930from clarifai .utils .misc import BackoffIterator
@@ -1204,7 +1205,6 @@ def stream_by_video_file(self,
12041205 # by getting the original start time ffprobe and either sending that to the model so it can adjust
12051206 # with the ts of the first frame (too fragile to do all of this adjustment in the client input stream)
12061207 # or by adjusting the timestamps in the output stream
1207- from clarifai .runners .utils import video_utils
12081208 stream = video_utils .convert_to_streamable (filepath )
12091209
12101210 # TODO accumulate reads to fill the chunk size
Original file line number Diff line number Diff line change 33import tempfile
44import threading
55
6- import av
76import requests
87
98from clarifai .runners .utils import stream_utils
9+ from clarifai .utils .misc import optional_import
10+
11+ av = optional_import ("av" , pip_package = "av" )
1012
1113
1214def stream_frames_from_url (url , download_ok = True ):
Original file line number Diff line number Diff line change 1+ import importlib
12import os
23import re
34import uuid
67from clarifai .errors import UserError
78
89
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+
933class Chunker :
1034 """Split an input sequence into small chunks."""
1135
You can’t perform that action at this time.
0 commit comments