#!/usr/bin/env python3 import gradio as gr import os from clip_interrogator import Config, Interrogator from huggingface_hub import hf_hub_download from share_btn import community_icon_html, loading_icon_html, share_js MODELS = ['ViT-L (best for Stable Diffusion 1.*)', 'ViT-H (best for Stable Diffusion 2.*)'] # download preprocesed file PREPROCESS_FILES = [ 'ViT-H-14_laion2b_s32b_b79k_artists.pkl', 'ViT-H-14_laion2b_s32b_b79k_flavors.pkl', 'ViT-H-14_laion2b_s32b_b79k_mediums.pkl', 'ViT-H-14_laion2b_s32b_b79k_movements.pkl', 'ViT-H-14_laion2b_s32b_b79k_trendings.pkl', 'ViT-L-14_openai_artists.pkl', 'ViT-L-14_openai_flavors.pkl', 'ViT-L-14_openai_mediums.pkl', 'ViT-L-14_openai_movements.pkl', 'ViT-L-14_openai_trendings.pkl', ] print("Download preprocessed cache files...") for file in PREPROCESS_FILES: path = hf_hub_download(repo_id="pharma/ci-preprocess", filename=file, cache_dir="cache") cache_path = os.path.dirname(path) # load BLIP and ViT-L https://huggingface.co/openai/clip-vit-large-patch14 config = Config(cache_path=cache_path, clip_model_path="cache", 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 inference(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_vith ci.config.blip_num_beams = 64 ci.config.chunk_size = 2048 ci.config.flavor_intermediate_count = 2048 if clip_model_name == MODELS[0] else 1024 image = image.convert('RGB') if mode == 'best': prompt = ci.interrogate(image) elif mode == 'classic': prompt = ci.interrogate_classic(image) else: prompt = ci.interrogate_fast(image) return prompt, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True) TITLE = """
Want some ideas for your next remodel?
The Remodel Dreamer will create a prompt of your current home or room to create some amazing spaces!