1616import threading
1717from pathlib import Path
1818from tqdm import tqdm
19+ import time
20+
1921logging .basicConfig (format = '%(message)s' , level = logging .INFO , stream = sys .stdout )
2022
2123sys .path .extend ([os .path .join (os .path .dirname (os .path .realpath (__file__ )), "openvino_common" )])
2224sys .path .extend ([os .path .join (os .path .dirname (os .path .realpath (__file__ )), ".." ,"tools" )])
2325from models_ov import (stable_diffusion_engine_genai )
24-
26+ from gimpopenvino . install_utils import *
2527
2628
2729# This dictionary is used to populate the drop-down model selection list.
299301
300302access_token = None
301303
302- # Enum for NPU Arch
303- class NPUArchitecture (Enum ):
304- ARCH_3700 = "3700" # Keem Bay
305- ARCH_3720 = "3720" # Meteor Lake and Arrow Lake
306- ARCH_4000 = "4000" # Lunar Lake
307- ARCH_NEXT = "FFFF" # Next Lake
308-
309304NPU_THRESHOLD = 43000
310305
311306def does_filename_match_patterns (filename , patterns ):
@@ -371,34 +366,9 @@ def download_file_with_progress(url, local_filename, callback, total_bytes_downl
371366 if callback (total_bytes_downloaded , total_file_list_size ):
372367 return downloaded_size
373368
369+ time .sleep (0.5 ) # give large files a chance to sync in their target directory.
374370 return downloaded_size
375371
376- def get_npu_architecture (core ):
377- """
378- Retrieves the NPU architecture using the OpenVINO core.
379-
380- Args:
381- core (ov.Core): The OpenVINO core instance.
382-
383- Returns:
384- NPUArchitecture: The detected architecture, or None if not found.
385- """
386- try :
387- available_devices = core .get_available_devices ()
388- if 'NPU' in available_devices :
389- architecture = core .get_property ('NPU' , 'DEVICE_ARCHITECTURE' )
390- for arch in NPUArchitecture :
391- if arch .value in architecture :
392- return arch
393- if core .get_property ("NPU" , "DEVICE_GOPS" )[ov .Type .i8 ] > 0 :
394- return NPUArchitecture .ARCH_NEXT
395- else :
396- return NPUArchitecture .ARCH_3700
397- return None
398- except Exception as e :
399- logging .error (f"Error retrieving NPU architecture: { str (e )} " )
400- return None
401-
402372def get_npu_driver_version (core ):
403373 try :
404374 available_devices = core .get_available_devices ()
@@ -428,7 +398,7 @@ def __init__(self, weight_path):
428398 self ._npu_driver_version = get_npu_driver_version (self ._core )
429399 self ._weight_path = weight_path
430400 self ._install_location = os .path .join (self ._weight_path , "stable-diffusion-ov" )
431- self ._npu_is_available = True if self ._npu_arch is not NPUArchitecture .ARCH_3700 and self ._npu_arch is not None else False
401+ self ._npu_is_available = True if self ._npu_arch is not NPUArchitecture .ARCH_3700 and self ._npu_arch is not NPUArchitecture . ARCH_NONE else False
432402 self .show_hf_download_tqdm = False
433403
434404 self .hf_api = HfApi ()
@@ -536,7 +506,7 @@ def is_model_installed(self, model_id):
536506 print (f"{ model_id } installation folder exists, but it is missing { required_bin_path } " )
537507 return False
538508
539- print ("model_id" ,model_id )
509+ # print("model_id",model_id)
540510 if "sd_3.0_med" in model_id or "sd_3.5_med" in model_id :
541511 install_subdir = g_supported_model_map [model_id ]["install_subdir" ]
542512 full_install_path = os .path .join (self ._weight_path , * install_subdir )
@@ -885,12 +855,10 @@ def _download_model(self, model_id):
885855 else :
886856 os .makedirs (full_install_path )
887857
888- print ("Inpainting optimun-cli full install path" ,full_install_path )
858+ # print("optimun-cli full install path",full_install_path)
889859 import subprocess
890860
891-
892- ppath = sys .executable
893- optimum_ex = ppath .replace ("python.exe" ,"optimum-cli.exe" )
861+ optimum_ex = sys .executable .replace ("python" , "optimum-cli" ).replace ("optimum-cli3" , "optimum-cli" )
894862
895863 output_file = Path (os .path .join (full_install_path , "export_output.log" ))
896864 if (model_id != "sd_15_inpainting" ):
@@ -914,6 +882,7 @@ def _download_model(self, model_id):
914882
915883 # Specify the file name
916884 file_name = "config.json"
885+ os .makedirs (os .path .dirname (full_install_path ), exist_ok = True )
917886
918887 # Write the data to a JSON file
919888 with open (os .path .join (full_install_path ,file_name ), 'w' ) as json_file :
@@ -933,6 +902,8 @@ def _download_model(self, model_id):
933902 if os .path .isdir (download_folder ):
934903 shutil .rmtree (download_folder , ignore_errors = True )
935904
905+
906+
936907 # To cache these models upfront as it takes a lot of time to load.
937908 if "sdxl_turbo" in model_id :
938909 model_name = "sdxl_turbo_square"
0 commit comments