Skip to content
This repository was archived by the owner on Nov 29, 2024. It is now read-only.

Commit 997395e

Browse files
committed
fix installation setup
1 parent 8835ca5 commit 997395e

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

visionscript/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@
5353
"vit": lambda self, folder: registry.vit_target(self, folder),
5454
"yolov8": lambda self, folder: registry.yolov8_target(self, folder),
5555
}
56+
57+
ALIASED_FUNCTIONS = {
58+
"isita": "classify",
59+
"find": "detect",
60+
"describe": "caption",
61+
"getcolors": "getcolours",
62+
}

visionscript/lang.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,31 @@
2828
from lark import Lark, UnexpectedCharacters, UnexpectedToken
2929
from PIL import Image
3030
from watchdog.observers import Observer
31+
from threading import Event, Thread
3132

32-
from visionscript import registry
33-
from visionscript.config import (CACHE_DIR, CACHE_DIRECTORY,
34-
CONCURRENT_MAXIMUM,
33+
from visionscript.config import (CACHE_DIRECTORY,
3534
CONCURRENT_VIDEO_TRANSFORMATIONS, DATA_TYPES,
3635
DEVICE, FASTSAM_DIR, FASTSAM_WEIGHTS_DIR,
3736
MAX_FILE_SIZE, STACK_MAXIMUM,
3837
SUPPORTED_INFERENCE_MODELS,
39-
SUPPORTED_TRAIN_MODELS, VIDEO_STRIDE)
38+
SUPPORTED_TRAIN_MODELS, VIDEO_STRIDE, ALIASED_FUNCTIONS)
4039
from visionscript.error_handling import (handle_unexpected_characters,
4140
handle_unexpected_token)
4241
from visionscript.grammar import grammar
4342
from visionscript.paper_ocr_correction import (line_processing,
4443
syntax_correction)
4544
from visionscript.pose import Pose
46-
from visionscript.rf_models import STANDARD_ROBOFLOW_MODELS
4745
from visionscript.state import init_state
4846
from visionscript.usage import USAGE, language_grammar_reference
4947

5048
# retrieve rf_models.json from ~/.cache/visionscript
5149
# this is where the user keeps a registry of custom models
5250
# which is combined with the standard RF models
53-
if not os.path.exists(CACHE_DIR):
54-
os.makedirs(CACHE_DIR)
51+
if not os.path.exists(CACHE_DIRECTORY):
52+
os.makedirs(CACHE_DIRECTORY)
5553

56-
if not os.path.exists(os.path.join(CACHE_DIR, "rf_models.json")):
57-
with open(os.path.join(CACHE_DIR, "rf_models.json"), "w") as f:
54+
if not os.path.exists(os.path.join(CACHE_DIRECTORY, "rf_models.json")):
55+
with open(os.path.join(CACHE_DIRECTORY, "rf_models.json"), "w") as f:
5856
json.dump({}, f)
5957

6058
parser = Lark(grammar, start="start")
@@ -68,18 +66,17 @@
6866

6967

7068
def run_command(cmd, directory=None):
71-
with subprocess.DEVNULL as DEVNULL:
72-
result = subprocess.run(
73-
cmd, cwd=directory, stdout=DEVNULL, stderr=subprocess.STDOUT, check=True
74-
)
69+
result = subprocess.run(
70+
cmd, cwd=directory, stderr=subprocess.STDOUT, check=True
71+
)
7572
if result.returncode != 0:
7673
raise ValueError(f"Command '{' '.join(cmd)}' failed to run.")
7774

78-
7975
def install_fastsam_dependencies():
76+
print("Installing FastSAM dependencies... (this may take a few minutes)")
8077
commands = [
8178
(
82-
["git", "-q", "clone", "https://github.com/CASIA-IVA-Lab/FastSAM"],
79+
["git", "clone", "-q", "https://github.com/CASIA-IVA-Lab/FastSAM"],
8380
CACHE_DIRECTORY,
8481
),
8582
(["pip", "install", "--quiet", "-r", "requirements.txt"], FASTSAM_DIR),
@@ -155,16 +152,8 @@ def _get_colour_name(rgb_triplet):
155152
return min_colours[min(min_colours.keys())]
156153

157154

158-
aliased_functions = {
159-
"isita": "classify",
160-
"find": "detect",
161-
"describe": "caption",
162-
"getcolors": "getcolours",
163-
}
164-
165-
166155
def map_alias_to_underlying_function(alias):
167-
return aliased_functions.get(alias, alias)
156+
return ALIASED_FUNCTIONS.get(alias, alias)
168157

169158

170159
class VisionScript:
@@ -2376,7 +2365,7 @@ def evaluate_tree(self, tree, main_video_thread=False):
23762365
self.state["ctx"]["last_profile_time"] = start_time
23772366
self.state["ctx"]["last_command"] = token
23782367

2379-
if token.value in aliased_functions:
2368+
if token.value in ALIASED_FUNCTIONS:
23802369
token.value = map_alias_to_underlying_function(token.value)
23812370

23822371
if token.type == "equality":
@@ -2670,8 +2659,6 @@ def evaluate_tree(self, tree, main_video_thread=False):
26702659
self.state["ctx"]["fps"] = 0
26712660
self.state["ctx"]["active_file"] = None
26722661

2673-
from threading import Event, Thread
2674-
26752662
self.state["ctx"]["camera"] = cv2.VideoCapture(0)
26762663

26772664
context = node.children

0 commit comments

Comments
 (0)