Spaces:
Running on Zero
Running on Zero
Commit ·
a8f45ac
1
Parent(s): 3ff6909
Temporarily disable model switching since it's dying on new 14GB RAM limit
Browse files2 unmodified lines3456789101112131415161718192021222324252627282930313215 unmodified lines48495051525354555657585960612 unmodified linesfrom clip_interrogator import Config, Interrogatorfrom share_btn import community_icon_html, loading_icon_html, share_jsMODELS = ['ViT-L (best for Stable Diffusion 1.*)', 'ViT-H (best for Stable Diffusion 2.*)']# load BLIP and ViT-L https://huggingface.co/openai/clip-vit-large-patch14config = Config(clip_model_name="ViT-L-14/openai")ci_vitl = Interrogator(config)ci_vitl.clip_model = ci_vitl.clip_model.to("cpu")# load ViT-H https://huggingface.co/laion/CLIP-ViT-H-14-laion2B-s32B-b79Kconfig.blip_model = ci_vitl.blip_modelconfig.clip_model_name = "ViT-H-14/laion2b_s32b_b79k"ci_vith = Interrogator(config)ci_vith.clip_model = ci_vith.clip_model.to("cpu")def image_analysis(image, clip_model_name):# move selected model to GPU and other model to CPUif clip_model_name == MODELS[0]:ci_vith.clip_model = ci_vith.clip_model.to("cpu")ci_vitl.clip_model = ci_vitl.clip_model.to(ci_vitl.device)ci = ci_vitlelse:ci_vitl.clip_model = ci_vitl.clip_model.to("cpu")ci_vith.clip_model = ci_vith.clip_model.to(ci_vith.device)ci = ci_vithimage = image.convert('RGB')image_features = ci.image_to_features(image)15 unmodified linesdef image_to_prompt(image, clip_model_name, mode):# move selected model to GPU and other model to CPUif clip_model_name == MODELS[0]:ci_vith.clip_model = ci_vith.clip_model.to("cpu")ci_vitl.clip_model = ci_vitl.clip_model.to(ci_vitl.device)ci = ci_vitlelse:ci_vitl.clip_model = ci_vitl.clip_model.to("cpu")ci_vith.clip_model = ci_vith.clip_model.to(ci_vith.device)ci = ci_vithci.config.blip_num_beams = 64ci.config.chunk_size = 20482 unmodified lines345678910111213141516171819202122232425262728293031323315 unmodified lines4950515253545556575859606162632 unmodified linesfrom clip_interrogator import Config, Interrogatorfrom share_btn import community_icon_html, loading_icon_html, share_jsMODELS = ['ViT-L (best for Stable Diffusion 1.*)']#, 'ViT-H (best for Stable Diffusion 2.*)']# load BLIP and ViT-L https://huggingface.co/openai/clip-vit-large-patch14config = Config(clip_model_name="ViT-L-14/openai")ci_vitl = Interrogator(config)# ci_vitl.clip_model = ci_vitl.clip_model.to("cpu")# load ViT-H https://huggingface.co/laion/CLIP-ViT-H-14-laion2B-s32B-b79K# config.blip_model = ci_vitl.blip_model# config.clip_model_name = "ViT-H-14/laion2b_s32b_b79k"# ci_vith = Interrogator(config)# ci_vith.clip_model = ci_vith.clip_model.to("cpu")def image_analysis(image, clip_model_name):# move selected model to GPU and other model to CPU# if clip_model_name == MODELS[0]:# ci_vith.clip_model = ci_vith.clip_model.to("cpu")# ci_vitl.clip_model = ci_vitl.clip_model.to(ci_vitl.device)# ci = ci_vitl# else:# ci_vitl.clip_model = ci_vitl.clip_model.to("cpu")# ci_vith.clip_model = ci_vith.clip_model.to(ci_vith.device)# ci = ci_vithci = ci_vitlimage = image.convert('RGB')image_features = ci.image_to_features(image)15 unmodified linesdef image_to_prompt(image, clip_model_name, mode):# move selected model to GPU and other model to CPU# if clip_model_name == MODELS[0]:# ci_vith.clip_model = ci_vith.clip_model.to("cpu")# ci_vitl.clip_model = ci_vitl.clip_model.to(ci_vitl.device)# ci = ci_vitl# else:# ci_vitl.clip_model = ci_vitl.clip_model.to("cpu")# ci_vith.clip_model = ci_vith.clip_model.to(ci_vith.device)# ci = ci_vithci = ci_vitlci.config.blip_num_beams = 64ci.config.chunk_size = 2048
app.py+24-22