Spaces:
Paused
Paused
Update app.py
Browse files48 unmodified lines495051525354120 unmodified lines17517617717817918018118 unmodified lines200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229567 unmodified lines79779879980080180280348 unmodified linesimport torchimport reimport timefrom PIL import ImageFilefrom utils import (download_things,120 unmodified linesself.last_load = datetime.now()self.inventory = []def update_storage_models(self, storage_floor_gb=30, required_inventory_for_purge=3):while get_used_storage_gb() > storage_floor_gb:if len(self.inventory) < required_inventory_for_purge:break18 unmodified linesdef load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):# download link model > model_nameif model_name.startswith("http"):yield f"Downloading model: {model_name}"model_name = download_things(DIRECTORY_MODELS, model_name, HF_TOKEN, CIVITAI_API_KEY)if not model_name:raise ValueError("Error retrieving model information from URL")if IS_ZERO_GPU:self.update_storage_models()vae_model = vae_model if vae_model != "None" else Nonemodel_type = get_model_type(model_name)dtype_model = torch.bfloat16 if model_type == "FLUX" else torch.float16if not os.path.exists(model_name):logger.debug(f"model_name={model_name}, vae_model={vae_model}, task={task}, controlnet_model={controlnet_model}")_ = download_diffuser_repo(repo_name=model_name,model_type=model_type,revision="main",token=True,)self.update_inventory(model_name)for i in range(68):if not self.status_loading:567 unmodified linesprompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")with gr.Accordion("Negative prompt", open=False, visible=True):neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt", value="bad anatomy, ((many hands, bad hands, missing fingers)), anatomical nonsense, ugly, deformed, bad proportions, bad shadow, extra limbs, missing limbs, floating limbs, disconnected limbs, malformed hands, poorly drawn, mutation, mutated hands and fingers, extra legs, interlocked fingers, extra arms, disfigured face, long neck, asymmetrical eyes, lowres, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry, duplicate, bad composition, text, worst quality, normal quality, low quality, very displeasing, monochrome, grayscale, black and white, desaturated, low contrast, muted tones, washed out, unfinished, incomplete, draft, logo, backlighting")with gr.Row(equal_height=False):set_params_gui = gr.Button(value="↙️", variant="secondary", size="sm")48 unmodified lines49505152535455120 unmodified lines17617717817918018118218318418518618 unmodified lines205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252567 unmodified lines82082182282382482582648 unmodified linesimport torchimport reimport timeimport threadingfrom PIL import ImageFilefrom utils import (download_things,120 unmodified linesself.last_load = datetime.now()self.inventory = []# Avoid duplicate downloadsself.active_downloads = set()self.download_lock = threading.Lock()def update_storage_models(self, storage_floor_gb=30, required_inventory_for_purge=4):while get_used_storage_gb() > storage_floor_gb:if len(self.inventory) < required_inventory_for_purge:break18 unmodified linesdef load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):lock_key = model_namewhile True:with self.download_lock:if lock_key not in self.active_downloads:self.active_downloads.add(lock_key)breakyield f"Waiting for existing download to finish: {model_name}..."time.sleep(1)try:# download link model > model_nameif model_name.startswith("http"):yield f"Downloading model: {model_name}"model_name = download_things(DIRECTORY_MODELS, model_name, HF_TOKEN, CIVITAI_API_KEY)if not model_name:raise ValueError("Error retrieving model information from URL")if IS_ZERO_GPU:self.update_storage_models()vae_model = vae_model if vae_model != "None" else Nonemodel_type = get_model_type(model_name)dtype_model = torch.bfloat16 if model_type == "FLUX" else torch.float16if not os.path.exists(model_name):logger.debug(f"model_name={model_name}, vae_model={vae_model}, task={task}, controlnet_model={controlnet_model}")_ = download_diffuser_repo(repo_name=model_name,model_type=model_type,revision="main",token=True,)self.update_inventory(model_name)except Exception as e:raise efinally:with self.download_lock:self.active_downloads.discard(lock_key)for i in range(68):if not self.status_loading:567 unmodified linesprompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")with gr.Accordion("Negative prompt", open=False, visible=True):neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt", value="bad anatomy, ((many hands, bad hands, missing fingers)), anatomical nonsense, ugly, deformed, bad proportions, bad shadow, extra limbs, missing limbs, floating limbs, disconnected limbs, malformed hands, poorly drawn, mutation, mutated hands and fingers, extra legs, interlocked fingers, extra arms, disfigured face, long neck, asymmetrical eyes, lowres, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry, duplicate, bad composition, text, worst quality, normal quality, low quality, very displeasing, desaturated, low contrast, muted tones, washed out, unfinished, incomplete, draft, logo, backlighting")with gr.Row(equal_height=False):set_params_gui = gr.Button(value="↙️", variant="secondary", size="sm")
app.py+46-23