Spaces:
Runtime error
Runtime error
File size: 2,172 Bytes
510ee71 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import platform
from os import path
from typing import List
from backend.device import is_openvino_device
from constants import DEVICE
from paths import get_file_name
def is_reshape_required(
prev_width: int,
cur_width: int,
prev_height: int,
cur_height: int,
prev_model: int,
cur_model: int,
prev_num_of_images: int,
cur_num_of_images: int,
) -> bool:
reshape_required = False
if (
prev_width != cur_width
or prev_height != cur_height
or prev_model != cur_model
or prev_num_of_images != cur_num_of_images
):
print("Reshape and compile")
reshape_required = True
return reshape_required
def enable_openvino_controls() -> bool:
return is_openvino_device() and platform.system().lower() != "darwin" and platform.processor().lower() != 'arm'
def get_valid_model_id(
models: List,
model_id: str,
default_model: str = "",
) -> str:
if len(models) == 0:
print("Error: model configuration file is empty,please add some models.")
return ""
if model_id == "":
if default_model:
return default_model
else:
return models[0]
if model_id in models:
return model_id
else:
print(
f"Error:{model_id} Model not found in configuration file,so using first model : {models[0]}"
)
return models[0]
def get_valid_lora_model(
models: List,
cur_model: str,
lora_models_dir: str,
) -> str:
if cur_model == "" or cur_model is None:
print(
f"No lora models found, please add lora models to {lora_models_dir} directory"
)
return ""
else:
if path.exists(cur_model):
return get_file_name(cur_model)
else:
print(f"Lora model {cur_model} not found")
if len(models) > 0:
print(f"Fallback model - {models[0]}")
return get_file_name(models[0])
else:
print(
f"No lora models found, please add lora models to {lora_models_dir} directory"
)
return ""
|