Spaces:
Runtime error
Runtime error
Update app.py
Browse files12 unmodified lines1314151617181921 unmodified lines414243444546472 unmodified lines50515253545556575859606142 unmodified lines10410510610710810911012 unmodified lines# --- Configuration Principale ---KRYPTO_LORA = {"repo": "Econogoat/Krypt0_LORA", "trigger": "Krypt0", "adapter_name": "krypt0"}GEMMA_MODEL_ID = "google/gemma-2-9b-it"BASE_IMAGE_MODEL = "black-forest-labs/FLUX.1-dev"# --- Pré-chargement sur CPU des éléments légers UNIQUEMENT ---21 unmodified linesfinal_prompt = prompt# --- Chargement à la demande ("Lazy Loading") des modèles sur le GPU ---# Cette section ne s'exécute qu'une seule fois, lors du premier appel.if pipe is None:print("Premier appel : Chargement du pipeline d'image sur GPU...")taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device_gpu)2 unmodified linesprint("Chargement du LoRA sur le pipeline GPU...")pipe.load_lora_weights(KRYPTO_LORA['repo'], low_cpu_mem_usage=False, adapter_name=KRYPTO_LORA['adapter_name'], token=HF_TOKEN)print("Pipeline d'image prêt.")# Monkey-patch pour la prévisualisationpipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)if enhance_prompt:if gemma_model is None:print(f"Premier appel d'amélioration : Chargement de {GEMMA_MODEL_ID} sur GPU avec quantization...")bnb_config_gpu = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_quant_type="nf4",42 unmodified linesyield final_image, seed, gr.update(visible=False)# Le reste du code (fonctions d'aide et UI) reste le mêmedef calculate_dimensions(aspect_ratio, resolution):resolution = int(resolution)if aspect_ratio == "Square (1:1)": width, height = resolution, resolution12 unmodified lines131415161718192021 unmodified lines4243444546472 unmodified lines50515253545556575859606142 unmodified lines10410510610710810912 unmodified lines# --- Configuration Principale ---KRYPTO_LORA = {"repo": "Econogoat/Krypt0_LORA", "trigger": "Krypt0", "adapter_name": "krypt0"}# --- CORRECTION DÉFINITIVE : Utilisation du bon ID de modèle, comme vous l'avez demandé ---GEMMA_MODEL_ID = "google/gemma-1.1-2b-it"BASE_IMAGE_MODEL = "black-forest-labs/FLUX.1-dev"# --- Pré-chargement sur CPU des éléments légers UNIQUEMENT ---21 unmodified linesfinal_prompt = prompt# --- Chargement à la demande ("Lazy Loading") des modèles sur le GPU ---if pipe is None:print("Premier appel : Chargement du pipeline d'image sur GPU...")taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device_gpu)2 unmodified linesprint("Chargement du LoRA sur le pipeline GPU...")pipe.load_lora_weights(KRYPTO_LORA['repo'], low_cpu_mem_usage=False, adapter_name=KRYPTO_LORA['adapter_name'], token=HF_TOKEN)print("Pipeline d'image prêt.")pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)if enhance_prompt:if gemma_model is None:print(f"Premier appel d'amélioration : Chargement de {GEMMA_MODEL_ID} sur GPU...")# La quantization est moins critique pour ce petit modèle, mais reste une bonne pratique.bnb_config_gpu = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_quant_type="nf4",42 unmodified linesyield final_image, seed, gr.update(visible=False)def calculate_dimensions(aspect_ratio, resolution):resolution = int(resolution)if aspect_ratio == "Square (1:1)": width, height = resolution, resolution
app.py+4-5