Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files74 unmodified lines75767778798081164 unmodified lines24624724824925025125225325425525625725835 unmodified lines29429529629729829930050 unmodified lines351352353354355356357123 unmodified lines481482483484485486487187 unmodified lines6756766776786796806816826832 unmodified lines68668768868969069169277 unmodified lines770771772773774775776158 unmodified lines93593693793893994086 unmodified lines102710281029103010311032154 unmodified lines118711881189119011911192119396 unmodified lines12901291129212931294129574 unmodified linesimport warningsfrom stablepy import loggerfrom diffusers import FluxPipeline# import urllib.parseimport subprocessos.system("pip list")164 unmodified linesself.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")35 unmodified linesself.status_loading = Trueyield f"Loading model: {model_name}"if vae_model == "BakedVAE":vae_model = model_name50 unmodified linesself.last_load = datetime.now()self.status_loading = Falseyield f"Model loaded: {model_name}"# @spaces.GPU(duration=59)@torch.inference_mode()123 unmodified linesvae_model = vae_model if vae_model != "None" else Noneloras_list = [lora1, lora2, lora3, lora4, lora5, lora6, lora7]vae_msg = f"VAE: {vae_model}" if vae_model else ""msg_lora = ""logger.debug(f"Config model: {model_name}, {vae_model}, {loras_list}")187 unmodified linesfor status, lora in zip(self.model.lora_status, self.model.lora_memory):if status:msg_lora += f"<br>Loaded: {lora}"elif status is not None:msg_lora += f"<br>Error with: {lora}"if msg_lora:info_images += msg_lora2 unmodified linesdownload_links = "<br>".join([f'<a href="{path.replace("/images/", f"/gradio_api/file={allowed_path}/")}" download="{os.path.basename(path)}">Download Image {i + 1}</a>'for i, path in enumerate(image_path)])77 unmodified lines)gr.Info(f"LoRAs in cache: {lora_cache_msg}")msg_request = f"Requesting {gpu_duration_arg}s. of GPU time.\nModel: {sd_gen.model.base_model_id}"if verbose_arg:gr.Info(msg_request)print(msg_request)158 unmodified lines"Image resolution": gr.update(value=1024),"Strength": gr.update(),"Prompt emphasis": gr.update(),}# Generate up to 7 LoRAs86 unmodified linesval = filtered_models[0]else:val = name_modelif key == "Hires upscaler":if val not in UPSCALER_KEYS:continue154 unmodified lineslabel="Style Prompt",interactive=True,)style_json_gui = gr.File(label="Style JSON File")style_button = gr.Button("Load styles")def load_json_style_file(json):96 unmodified linesimage_resolution_gui,strength_gui,prompt_syntax_gui,lora1_gui,lora_scale_1_gui,lora2_gui,74 unmodified lines75767778798081164 unmodified lines24624724824925025125225325425525625725835 unmodified lines29429529629729829930050 unmodified lines351352353354355356357123 unmodified lines481482483484485486487187 unmodified lines6756766776786796806816826832 unmodified lines68668768868969069169277 unmodified lines770771772773774775776158 unmodified lines93593693793893994094186 unmodified lines102810291030103110321033103410351036103710381039104010411042154 unmodified lines119711981199120012011202120396 unmodified lines130013011302130313041305130674 unmodified linesimport warningsfrom stablepy import loggerfrom diffusers import FluxPipelineimport urllib.parseimport subprocessos.system("pip list")164 unmodified linesself.active_downloads.add(lock_key)breakyield f"Waiting for existing download to finish: {escape_html(model_name)}..."time.sleep(1)try:# download link model > model_nameif model_name.startswith("http"):yield f"Downloading model: {escape_html(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")35 unmodified linesself.status_loading = Trueyield f"Loading model: {escape_html(model_name)}"if vae_model == "BakedVAE":vae_model = model_name50 unmodified linesself.last_load = datetime.now()self.status_loading = Falseyield f"Model loaded: {escape_html(model_name)}"# @spaces.GPU(duration=59)@torch.inference_mode()123 unmodified linesvae_model = vae_model if vae_model != "None" else Noneloras_list = [lora1, lora2, lora3, lora4, lora5, lora6, lora7]vae_msg = f"VAE: {escape_html(vae_model)}" if vae_model else ""msg_lora = ""logger.debug(f"Config model: {model_name}, {vae_model}, {loras_list}")187 unmodified linesfor status, lora in zip(self.model.lora_status, self.model.lora_memory):if status:msg_lora += f"<br>Loaded: {escape_html(lora)}"elif status is not None:msg_lora += f"<br>Error with: {escape_html(lora)}"if msg_lora:info_images += msg_lora2 unmodified linesdownload_links = "<br>".join([f'<a href="{path.replace("/images/", f"/gradio_api/file={allowed_path}/")}" download="{escape_html(os.path.basename(path))}">Download Image {i + 1}</a>'for i, path in enumerate(image_path)])77 unmodified lines)gr.Info(f"LoRAs in cache: {lora_cache_msg}")msg_request = f"Requesting {gpu_duration_arg}s. of GPU time.\nModel: {escape_html(sd_gen.model.base_model_id)}"if verbose_arg:gr.Info(msg_request)print(msg_request)158 unmodified lines"Image resolution": gr.update(value=1024),"Strength": gr.update(),"Prompt emphasis": gr.update(),"VAE": gr.update(),}# Generate up to 7 LoRAs86 unmodified linesval = filtered_models[0]else:val = name_modelif key == "VAE":val_unquote = urllib.parse.unquote(str(val))filtered_vaes = [v for v in vae_model_list if str(val) in v or val_unquote in v]if filtered_vaes:val = filtered_vaes[0]elif val in ["None", "BakedVAE"]:val = valelse:continueif key == "Hires upscaler":if val not in UPSCALER_KEYS:continue154 unmodified lineslabel="Style Prompt",interactive=True,)style_json_gui = gr.File(label="Style JSON File", file_count="single", file_types=[".json"])style_button = gr.Button("Load styles")def load_json_style_file(json):96 unmodified linesimage_resolution_gui,strength_gui,prompt_syntax_gui,vae_model_gui,lora1_gui,lora_scale_1_gui,lora2_gui,
app.py+22-11